用htaccess RewriteRule替换url的一部分

时间:2014-06-16 19:11:58

标签: .htaccess

我有一部分网址要替换为htaccess:

如何将root/aaa/bbb/css/images/ddd.image.png替换为root/aaa/css/images/ddd.image.png

我在根文件夹中的.htaccess中尝试了这段代码:

RewriteEngine On
RewriteRule ^aaa/bbb/(.*) /aaa/$1 [L,QSA,R=301]

在aaa文件夹中,有.htaccess:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

1 个答案:

答案 0 :(得分:1)

您需要在/aaa/.htaccess中使用此规则:

RewriteEngine On
RewriteBase /aaa/

RewriteRule ^bbb/(.+)$ $1 [L,NC,R=301,NE]

RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

RewriteRule ^ index.php [L]