问题
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