【问题标题】:.htaccess exception for subdomain not working子域的 .htaccess 异常不起作用
【发布时间】: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


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 2018-08-07
    • 1970-01-01
    • 2013-02-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-16
    • 2016-06-11
    相关资源
    最近更新 更多