.htaccess 图像重写规则

.htaccess 图像重写规则,.htaccess,mod-rewrite,url-rewriting,.htaccess,Mod Rewrite,Url Rewriting,我必须在我的网站上重写一些url。我已将其放入我的htaccess以进行此更改: --> 现在我必须以这种方式重写图像url。具有此路径的每个图像:example.com/john/images/a.jpg 应指向物理路径:example.com/accounts/john/images/a.jpg 我该怎么做 注意:“John”不是固定的,但可以是所有可能的单词。您可以尝试以下脚本: RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUE

我必须在我的网站上重写一些url。我已将其放入我的htaccess以进行此更改: -->

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

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

我该怎么做


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

您可以尝试以下脚本:

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]

你能接受我的回答,把这个问题标记为已解决吗?
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]