0

我有以下 .htaccess 文件设置以将我的所有 .co.uk 站点流量重定向到站点的新 .com 域名。

# Redirect all requests NOT made under www.domain.com
RewriteCond %{REQUEST_URI} !/admin
#RewriteCond %{HTTP_HOST} !^www\.domain-name\.com [NC]

#RewriteRule ^(.*)$ http://www.domain-name\.com/$1 [R=301,L]

RewriteCond %{HTTP_HOST} !^www\.domain-name\.com

RewriteRule (.*) http://www.domain-name.com/$1 [R=301,L]

RewriteCond %{REQUEST_FILENAME}       !-d

RewriteCond %{REQUEST_FILENAME}       !-f

RewriteRule ^(.+) index.php?seo_path=$1&%{QUERY_STRING} [L]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/

RewriteRule ^index\.php$ http://www.domain-name.com/ [R=301,L]

ErrorDocument 404 /page-not-found.php

但是,我想将 .co.uk/blog 重定向到新的 .com/blog,但是,目前,当您访问 .co.uk/blog 时,它会重定向到 .com 主页。- 我相信这是因为;

   RewriteRule ^(.+) index.php?seo_path=$1&%{QUERY_STRING} [L]

如果 URL 以 /blog 结尾,我将如何添加条件来否决这一点?

4

1 回答 1

1

实际上,您的第一条规则是.co.uk需要.com跳过后续规则/blog

有这样的规则:

# if request_uri doesn't start with /blog or /admin
RewriteCond %{REQUEST_URI} !^/(admin|blog) [NC]
RewriteCond %{HTTP_HOST} !^(www\.)?domain-name\.com$ [NC]
RewriteRule ^ http://www.domain-name.com%{REQUEST_URI} [R=301,L]

RewriteCond %{REQUEST_FILENAME}       !-d
RewriteCond %{REQUEST_FILENAME}       !-f
RewriteRule ^(.+)$ /index.php?seo_path=$1 [L,QSA]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php[\s?] [NC]
RewriteRule ^ http://www.domain-name.com/ [R=301,L]

ErrorDocument 404 /page-not-found.php
于 2013-10-02T10:03:05.283 回答