我有以下.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结束/博客,我将如何添加条件来否决此内容?
答案 0 :(得分: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