如何设置.htaccess文件以排除子目录?
我目前的网站设置如下:如何设置.htaccess文件以排除子目录?,.htaccess,.htaccess,我目前的网站设置如下: 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
是根域example.com
文件将所有请求重定向到根URL到.htaccess
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
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]