Rewrite image path with htaccess?

一个人想着一个人 提交于 2019-12-11 10:29:58

问题


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]


来源:https://stackoverflow.com/questions/14792773/rewrite-image-path-with-htaccess

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!