重写图像的规则

时间:2016-01-26 16:28:17

标签: .htaccess mod-rewrite url-rewriting

我必须在我的网站上重写一些网址。我把它放在我的htaccess中进行这个改变: 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]

现在我必须以这种方式重写图像网址。具有此路径的每张图片: example.com/john/images/a.jpg

应指向物理路径: example.com/accounts/john/images/a.jpg

我该怎么做?

注意:“John”不是固定的,但可以是每个可能的单词。

1 个答案:

答案 0 :(得分:1)

您可以尝试以下脚本:

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]