0

我目前通过以下方式设置网站:

  • example.com是根域
  • .htaccess文件将所有请求重定向到根 URL 到blog.example.com

这是因为blog子域是主域的镜像,并且将在未来使用。

问题是还有第二个域:product.com指向example.com/product.

配置.htaccess文件后,所有传入请求都映射到blog.example.com.

这意味着 go toproduct.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
4

1 回答 1

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]
于 2013-08-02T21:30:12.503 回答