【发布时间】:2014-10-24 06:33:39
【问题描述】:
在提交这个帖子之前我已经搜索了stackoverflow,但我没有运气:-S
我有一个包含复杂 .htaccess 文件的网站,如下所示:
这部分用于重定向(X.2nate dot com --> 2nate dot com/api/x),效果很好
########### API Redirection Section ##########
RewriteEngine On
# Extract the subdomain part of domain.com
RewriteCond %{HTTP_HOST} ^([^\.]+)\.2nate\.com$ [NC]
# Check that the subdomain part is not www and ftp and mail
RewriteCond %1 !^(www|ftp|mail|charge)$ [NC]
# Redirect all requests to the original url /blog
RewriteRule ^.*$ https://2nate.com/api/%1 [L]
这部分用于将非 SSL 请求重定向到 SSL 协议:
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
这部分是用WWW重定向到非WWW地址:
RewriteCond %{HTTP_HOST} ^www\.2nate\.com$
RewriteRule ^/?$ "http\:\/\/2nate\.com\/" [R=301,L]
问题是:
当我尝试访问“charge” dot mywebsite dot com(charge 是我主机中的一个真实子域)时,我无法访问相关页面并且它正在重定向到主页!
我认为这部分有问题:
RewriteCond %{HTTP_HOST} ^www\.2nate\.com$
RewriteRule ^/?$ "http\:\/\/2nate\.com\/" [R=301,L]
因为当我删除这部分时,一切正常(重定向到非 WWW 除外)。
感谢任何帮助。
【问题讨论】:
标签: .htaccess mod-rewrite redirect ssl wildcard