2015-09-27 74 views
2

我正在嘗試這麼做:htaccess重定向域名爲https,具有參數的子域名爲http

強制https爲我的主域。

http或https://www.domain.com - >https://domain.com
http或https://domain.com - >https://domain.com

這是域htaccess的編碼

RewriteEngine On 
RewriteCond %{HTTPS} off 
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L] 

這是工作的罰款

但不適合子域

我想要結果爲

https://www.domain.com/index.php?username=abc => http://abc.domain.com 
http://www.domain.com/index.php?username=abc => http://abc.domain.com 

並始終刪除www和https到http。

,但不知道怎麼寫子站點

+0

這是我的域的htaccess RewriteEngine敘述在 的RewriteCond%{HTTPS}關閉 重寫規則HTTPS(*)://%{HTTP_HOST}%{REQUEST_URI} [R,L] ,但我不想法HTTP子域 – Amy

+0

這個問題已經在這裏找到答案:http://stackoverflow.com/questions/4398951/force-ssl-https-using-htaccess-and-mod-rewrite – Joro

+0

@Joro對不起,沒有,這個問題不_回答這個問題。 – arkascha

回答

1

這將首先檢查是否需要重定向到基於查詢字符串中的用戶名參數,如果請求的index.php一個子域htaccess的代碼。然後,當重寫到該子域時,它將複製整個查詢字符串,但省略其中的用戶名參數,同時保留所有其他參數。

第二部分將檢查您的主域帶或不帶www,然後執行它的https,如果我們尚未決定重定向到一個子域。

RewriteEngine On 

#match either the www subdomain or no subdomain 
    RewriteCond %{HTTP_HOST} ^(?:www.)?(?:domain\.com)$ 
#which request index.php 
    RewriteCond %{REQUEST_URI} ^/index\.php 
#and contain a username paramater 
    RewriteCond %{QUERY_STRING} ^(.*?)(?:^|&)username=([^&]+)(.*?)$ 
#then rewrite them to username.domain.com without the username parameter 
    RewriteRule^http://%2.domain.com%{REQUEST_URI}?%1%3 [R,QSA,L] 

#match either the www subdomain or no subdomain 
    RewriteCond %{HTTP_HOST} ^(?:www.)?(?:domain\.com)$ 
#which was requested without https 
    RewriteCond %{HTTPS} off 
#then redirect to https 
    RewriteRule^https://%{HTTP_HOST}%{REQUEST_URI} [R,L] 
+0

- >感謝兄弟從心底的一個小問題,它的ok用戶名= abc然後abc.domain.com url正在工作,但是無法使用username = abc獲取數據 – Amy

+0

如果你想包含username參數, :'RewriteRule^http://%2.domain.com% {REQUEST_URI} [R,L]' – Ultimater

+0

on after line – Amy