2014-08-30 60 views
0

我搜索计算器提交此线程之前,但我没有运气:-S不包括htaccess的一个子域名重定向

我有一个网站,如下一个复杂的.htaccess文件:

这部分是重定向(X.2nate科网 - > 2nate点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] 

,问题是:

当我试图访问“充电”点mywebsite点com(电荷一个真正的子域在我的主机)我无法访问相关页面,它重定向到主页面!

我认为问题是这一部分:

RewriteCond %{HTTP_HOST} ^www\.2nate\.com$ 
RewriteRule ^/?$ "http\:\/\/2nate\.com\/" [R=301,L] 

因为当我删除了这部分,一切都OK了(除了重定向到非WWW)。

任何帮助表示赞赏。

回答

0

问题实际上是这样的规则:

RewriteRule ^.*$ https://2nate.com/api/%1 [L] 

由于您使用的目标URL http://它不是一种无声的重写,但会成为外部重定向。

有你的.htaccess这样的:

RewriteEngine On 

RewriteCond %{HTTPS} off 
RewriteRule^https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE] 

RewriteCond %{HTTP_HOST} ^www\.2nate\.com$ 
RewriteRule^http://2nate.com%{REQUEST_URI} [R=301,L,NE] 

# Extract the subdomain part of domain.com 
RewriteCond %{HTTP_HOST} ^((?!www)[^.]+)\.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 ^.*$ /api/%1 [L] 
+0

感谢您的时间,但它不是我想要的方式工作。 这只是影响静音/外部重定向(我不想改变这些设置)。 我只想访问charge.2nate.com。 – 2014-08-31 11:54:55

+0

我有另一个真正的子域“博客”-dot-mywebsite-dot-com,它运行良好。 – 2014-08-31 12:32:48

+0

我想现在我没有得到你的问题?哪个网址不适合你? – anubhava 2014-08-31 14:45:06