301重定向的RewriteRule条件

时间:2014-10-07 15:15:54

标签: apache .htaccess mod-rewrite redirect

我必须重新命名URL的一部分,这会影响几十个网页:

http://www.example.com/old/web-pagehttp://www.example.com/new/web-page

到目前为止,我有:

RewriteRule old/(.*) http://www.example.com/new/$1 [R=301,L]

但我已经读过RewriteRule can clash,我正在使用.htaccess:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>

所以,我有两个问题:RewriteRule是否正确;我是否会遇到某种冲突?

1 个答案:

答案 0 :(得分:1)

301规则放在RewriteEngine On行下面

<IfModule mod_rewrite.c>
RewriteEngine On

RewriteRule old(/.*)?$ /new$1 [R=301,L,NC]

RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>