2016-08-12 88 views
0
RewriteEngine On 
RewriteCond %{HTTP_USER_AGENT} libwww-perl.* 
RewriteRule .* ? [F,L] 
RewriteCond %{HTTPS} off 

RewriteCond %{HTTPS_HOST} !^www.website.com$ [NC] 
RewriteRule ^(.*)$ https://www.website.com/$1 [L,R=301] 

我用這個重定向:爲HTTPS URL htaccess的規範化(HTTP:// WWW)

到https
  • http://wwwhttps://www

    我想這個代碼改變HTTP到HTTPS,但它仍然無法正常工作。有什麼我做錯了嗎?

  • 回答

    1

    您可以使用:

    RewriteEngine On 
    RewriteCond %{HTTP_USER_AGENT} libwww-perl.* 
    RewriteRule .* ? [F,L] 
    
    RewriteCond %{HTTPS} off [OR] 
    RewriteCond %{HTTPS_HOST} !^www.website.com$ [NC] 
    RewriteRule ^(.*)$ https://www.website.com/$1 [L,R=301] 
    

    隨着[OR]

    0
    RewriteCond %{HTTPS} off 
    RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 
    RewriteCond %{HTTP_HOST} !^www\. 
    RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 
    

    此代碼爲我工作。謝謝!