我目前通过以下方式设置网站:
example.com
是根域.htaccess
文件将所有对根URL的请求重定向到blog.example.com
这是因为blog
子域是主域的镜像,将会向前发展。
问题是有第二个域:product.com
指向example.com/product
。
在配置.htaccess
文件后,所有传入请求都会映射到blog.example.com
。
这意味着转到product.com
会产生blog.example.com/product
,其中理想情况是example.com/product
,所有其他传入请求都会重定向到blog.example.com
。
我的.htaccess
文件的副本如下:
# Block access to the root site
RewriteCond %{HTTP_HOST} ^(example\.com)$ [NC]
# Whitelist specific areas of the root site
# e.g category slugs or page slugs you want to remain viewable
RewriteCond %{REQUEST_URI} !/blog.* [NC]
RewriteCond %{THE_REQUEST} !/blog.* [NC]
# Set like-to-like redirect URL for anything not whitelisted
RewriteRule (.*) http://blog\.example\.com/$1 [R=301,L]
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
# add a trailing slash to /wp-admin
RewriteRule ^wp-admin$ wp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^(wp-(content|admin|includes).*) $1 [L]
RewriteRule ^(.*\.php)$ $1 [L]
RewriteRule . index.php [L]
我如何以下列方式构建规则:
product.com
重定向到example.com/product
example.com
重定向到blog.example.com
答案 0 :(得分:1)
这应该有效:
RewriteEngine On
# redirect anything that is different than /blog and /product to blog.example.com
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteCond %{REQUEST_URI} !/blog.* [NC]
RewriteCond %{REQUEST_URI} !/product.* [NC]
RewriteRule ^(.*)$ http://blog.example.com/$1 [R=301,L]