我想實現99%的工作,但有一個小問題。HTACCESS 301重定向規則指向實時URL的所有URL變化
比方說,我活的URL是https://www.example.com/sample-page/
我希望所有的以下網址的變化重定向到URL直播與301個狀態。
http://example.com/sample-page/
http://www.example.com/sample-page/
https://example.com/sample-page/
的上述所有應該重定向到https://www.example.com/sample-page/
我設法通過下面顯示的htaccess的規則得到這個工作。
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} !^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
上述規則的問題是:http://example.com/sample-page/做雙重定向。
http://eyeacademy.com/expert-eye-examination/
301 Moved Permanently
https://eyeacademy.com/expert-eye-examination/
301 Moved Permanently
https://www.eyeacademy.com/expert-eye-examination/
200 OK
正如您所看到的,http重定向到https,然後https非www重定向到https www。我一直在嘗試對這個規則進行一些調整,然後閱讀,但我相信這裏有人會有更快更強大的解決方案?
把https規則最後? – 123
試過了。它通過添加www.www來打破https非www網址。到域。 –
以'L'取代第一條規則。 – 123