2012-11-09 31 views
-1

我在我的.htaccess文件中使用以下內容,強制在任何用戶訪問我的網站時使用https而不使用https。刪除「www。」 from url with strongful https

但是,如果用戶訪問https://www.mysite.co,我希望能夠從請求中刪除www。

請問你能告訴我什麼我需要在我的.htaccess文件中修改,以便從url中刪除www,同時保持有力的https?

謝謝,

最大。

RewriteEngine On 
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://mysite.co/$1 [R,L] 
+0

重複:http://stackoverflow.com/questions/6399406/remove-www-from-https –

+0

看到這個職位......這是一個很好的解釋 http://stackoverflow.com/questions/10725357/redirect-https-to-non-www-and-http-to-www/10726167#10726167 – Zak

+0

...如果它已經有東西的副本,請將它作爲副本關閉* - 服務器故障已經存在有一百萬mo.d_rewrite的問題,你的重複目標會比[我們]更好(http://serverfault.com/questions/214512/everything-you-ever-wanted-to-know-about-mod-rewrite-規則,但是很害怕到) – voretaq7

回答

2

重寫2次。

RewriteEngine On 

RewriteCond %{HTTPS} off 
RewriteRule ^(.*)$ https://mysite.co/$1 [R,L] 

RewriteCond %{HTTPS} on 
RewriteCond %{HTTP_HOST} ^www\. [NC] 
RewriteRule ^(.*)$ https://mysite.co/$1 [R,L] 
+0

在從Zak和aam1r的鏈接良好的評論。 – CoffeeMonster

+0

當我使用'www.mysite.co'時,它起作用,但當我使用'https:// www.mysite.co' –

+0

時出錯 - 我的錯誤 - 在查詢字符串而不是http_host上匹配。 – CoffeeMonster

相關問題