views:

28

answers:

3

I have my mod_rewrite set up so that it redirects all requests that aren't targeting existing files or directories to index.php?req=* where * is the request.

Works all fine but when I send the browser to something like this:

http://myurl/A/B/C

The browser tries to find all images, stylesheets in the non-existing folder C. How can I make the browser to look in / instead of the 'virtual' directory?

Do I have to put an absolute path everywhere?

A: 

You need to use absolute URLs (or at least absolute URL paths) when referencing the resources. So http://example.com/foo/bar or /foo/bar instead of foo/bar or ./foo/bar.

Because otherwise the URL path of the current document is used as base path the relative paths are then resolved from.

Another way would be to change the base URL with the base element like:

<base href="/">

This will change the base URL path to /. But note that this will affect all relative URLs and not just those with a relative URL path.

Gumbo
A: 

Yes. Either like this:

<img src="/image.jpg" />

or using HTML's <base>.

I'd prefer altering the src, though. It's less of a hassle.

middus
Could you maybe assist me writing a regex for this?Doesn't seem too hard but I can't get it working.It should just use preg_replace to replace `(href|src)="!/(.+)"` with `/$1`.
humgl
A: 

Do I have to put an absolute path everywhere?

Yes.

Qtax