Rewrite image path with htaccess?

2019-07-23 14:23发布

问题:

I have these old site and it has the image url in all of its .htm files like this below,

<img border="0" src="images/logo.jpg" alt="xxx" width="170" height="150">

I want to know if I can add an absolute path before all the image URLs with htaccess.

For instance,

<img border="0" src="http://localhost/mysite/local/applications/bin/oldsite/images/logo.jpg" alt="xxx" width="170" height="150">

Is it possible?

Or do I have to change the image path manually file by file?

My attempt,

RewriteRule ^(.*\.(gif|jpg|png))$ local/applications/bin/oldsite/images/$1 [QSA,L]

not working of course!

回答1:

Your rule

RewriteRule ^(.*\.(gif|jpg|png))$ local/applications/bin/oldsite/images/$1 [QSA,L]

would redirect images/image.jpg to local/applications/bin/oldsite/images/images/image.jpg

Lose the images/ part from the end of your rule:

RewriteRule ^(.*\.(gif|jpg|png))$ local/applications/bin/oldsite/$1 [QSA,L]


回答2:

I made it with this rule,

RewriteRule ^images\/(.*\.(gif|jpg|png))?$ local/applications/bin/oldsite/images/$1 [QSA,L]