重定向与RewriteRule冲突,可能是什么导致它?

时间:2014-09-17 01:14:10

标签: .htaccess

我目前正在从olddomain.com切换到newdomain.com,在.htaccess的顶部,我有以下Redirect

Redirect 301 /pageA/ http://newsite.com/pageA
Redirect 301 /pageB/ http://newsite.com/pageB
Redirect 301 /pageCa/ http://newsite.com/pageCb
Redirect 301 /pageD/ http://newsite.com/pageD

正如你在那里看到的,其中一个重定向," pageCa"更改为" pageCb"有时301优先。如果我稍后输入相同的网址,就会像301那里的网站一样,而下面的网址都会生效。

# Catch all for pages different from the Redirects
RewriteCond %{HTTP_HOST} ^oldsite.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www.oldsite.com [NC]
RewriteRule ^(.*)$ http://newsite.com/$1 [L,R=301,NC]
  • 可能导致此冲突的原因是什么?

两个域都在同一个DocumentRoot下,其他所有域似乎都可靠地运行。

我的完整.htaccess

AddHandler application/x-httpd-php54s .php

Redirect 301 /pageA/ http://newsite.com/pageA
Redirect 301 /pageB/ http://newsite.com/pageB
Redirect 301 /pageCa/ http://newsite.com/pageCb
Redirect 301 /pageD/ http://newsite.com/pageD

ErrorDocument 404 /404

<IfModule mod_rewrite.c>
RewriteEngine On
Options +SymLinksIfOwnerMatch

# Removes www
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]

# Catch all for pages different from the Redirects
RewriteCond %{HTTP_HOST} ^oldsite.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www.oldsite.com [NC]
RewriteRule ^(.*)$ http://newsite.com/$1 [L,R=301,NC]

# Unless directory, remove trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/$ http://newsite.com/$1 [R=301,L]

# Redirect external .php requests to extensionless url
RewriteCond %{THE_REQUEST} ^(.+)\.php([#?][^\ ]*)?\ HTTP/
RewriteRule ^(.+)\.php$ http://newsite.com/$1 [R=301,L]

# Maps to php files
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^\.]+)$ $1.php [NC]

# All 404 requests
RewriteCond %{REQUEST_URI} ^/404$
RewriteRule ^(.*)$ http://newsite.com/404 [L]

</IfModule>

1 个答案:

答案 0 :(得分:0)

好吧,似乎在“全部捕获”而不是重定向之前使用以下内容:

如果页面名称保持不变,则更改网址:

RewriteRule ^oldsite.com/pageA/?$ http://newsite.com/pageA [L]

两者都不同:

RewriteRule ^pageCa/?$ http://newsite.com/pageCb [L]

由于