子域无效的.htaccess异常

时间:2015-02-01 20:22:02

标签: php .htaccess exception redirect subdomain

我想使用.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]

1 个答案:

答案 0 :(得分:1)

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

如果在测试时进行实际重定向,则可以在重写中使用[R=302,L],然后在看到它工作时可以删除302。