.htaccess 子域的异常不起作用


.htaccess exception for subdomain not working

我想使用 .htaccess 将我的网站的根目录重定向到子文件夹

应该是:

mysite.com -> 重定向至 mysite.com/2015
mysite.com/something -> 无重定向
sub.mysite.com -> 无重定向

目前发生的情况是,sub.mysite.com 也被重定向到 mysite.com/2015。

这是我目前的.htaccess。已经为子域尝试了十几个例外,但没有一个奏效。

RewriteEngine On
RewriteBase /
# Redirect WWW to non-WWW, vice versa
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^www'.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^www'.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
  
# Some security rules
Options +FollowSymLinks -MultiViews
Options +Indexes
AcceptPathInfo Off
#Custom 404 Page
ErrorDocument 404 /404.php
# Video types for mobile
AddType video/ogg .ogv
AddType video/mp4 .mp4
AddType video/webm .webm
# Invoice Redirect
RewriteRule ^b/(.*)$ ./modules/gateways/boletocefsinco/boleto_cef_sigcb.php?via=$1 [L,NC]
# New Site Redirect
RewriteCond %{HTTP_HOST} ^(www.)?mysite.com$
RewriteCond %{REQUEST_URI} !^/2015/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /2015/$1
RewriteCond %{HTTP_HOST} ^(www.)?mysite.com$
RewriteRule ^(/)?$ 2015/index.php [L]

测试 .htaccess 规则时,您应该清除浏览器缓存或尝试不同的浏览器,因为这些内容会被缓存。

如果在测试时进行实际重定向,您也可以在重写规则中使用[R=302,L],那么您可以在看到 302 工作时将其删除。