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