mod_rewrite how to show images in a certain dir
I am starting to use mod_rewrite and would like to know if the below is possible...
Rewrit开发者_开发问答eRule ^test/([^/]*)/$ /test.php?x=$1 [NC,L]
That works as expected however, once the HTML generates I use relative paths to images/stylesheets etc such as <img src="include/image.jpg" />
which now no longer shows.
How can I get around this?
Many Thanks
One way to do it is to add a rule to skip requests that end in standard image file suffixes:
RewriteRule \.(gif|jpe?g|png|ico)$ - [NC,S=1]
RewriteRule ^test/([^/]*)/$ /test.php?x=$1 [NC,L]
There are several possibilities:
- Don't use relative paths.
- Add a
<base>
tag to your HTML. - Rewrite the image URLs too:
RewriteRule ^test/include/(.*)$ /include/$1 [NC,L]
精彩评论