【发布时间】:2015-02-01 20:22:02
【问题描述】:
我想使用 .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]
【问题讨论】:
-
您是否清除了浏览器缓存或尝试使用其他浏览器?您还应该在 RewriteCond 中转义您的
.。 -
就是这样,哈哈。它奏效了。
-
没问题。很高兴你得到它。我会留下一个答案让你接受,这样问题就不会悬而未决。
标签: php .htaccess exception redirect subdomain