RewriteRule for images

佐手、 提交于 2019-12-24 17:46:09

问题


I have to rewrite some url on my site. I've put this in my htaccess to make this change: http://example.com/john/?a=1&b=2 --> http://example.com/index.php?account=john&a=1&b=2

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9_-]+)/?$ ./index.php?account=$1 [NC,QSA,L]

Now I have to rewrite images url in this way. Every image with this path: example.com/john/images/a.jpg

Should point to phisical path: example.com/accounts/john/images/a.jpg

How can I do that?

Note: "John" is not fixed but can be every possible word.


回答1:


You can try this script:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ /index.php?account=$1 [NC,QSA,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/images/([^/]+).jpg$ /accounts/$1/images/$2.jpg [NC,L]


来源:https://stackoverflow.com/questions/35018802/rewriterule-for-images

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