Rewrite image path with htaccess?

2019-07-23 14:02发布

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!

2条回答
虎瘦雄心在
2楼-- · 2019-07-23 14:29

I made it with this rule,

RewriteRule ^images\/(.*\.(gif|jpg|png))?$ local/applications/bin/oldsite/images/$1 [QSA,L]
查看更多
叼着烟拽天下
3楼-- · 2019-07-23 14:36

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]
查看更多
登录 后发表回答