Reputation: 2055
I've got an .htaccess file that reads as follows:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
There's an image on index.php that should always display, however when I navigate to a rewritten path, the request for the image is prepended with that path. So the "categories" section, while it should still display my foo.png at images/foo.png now has the path categories/images/foo.png
Can I fix this strictly with .htaccess rewrite rules? If so, how?
Upvotes: 0
Views: 273
Reputation: 143866
This sounds like a relative vs absolute URL mix-up. When you have paths like http://domain.com/category/post/name
the relative URI base is /category/post
and all relative links that get served in the content returned by the webserver will have that prepended to it by the browser. In order to tell the browser what the real URI base is, you can include this in your headers:
<base href="/">
Or you can simply change all your relative URLs to absolute URLs.
Upvotes: 0
Reputation: 2856
A more simple solution would be to use a src for the img-element in your html based on the root-folder of your site. (If it's just for that one image...)
For example: http://www.site.com
<img src="/images/header.jpeg" />
This will always refer to http://www.site.com/images/header.jpeg, no matter what folder you're in.
Upvotes: 1
Reputation: 5490
This should take any request for the image and rewrite it to go the root /images/foo.png:
RewriteRule ^.*/images/foo.png$ /images/foo.png
Note that if you have a different image located at somewhere/images/foo.png, requests for that will also be rewritten to /images/foo.png, unless you write specific exceptions for it.
Upvotes: 0