[英]HTTP to HTTPS and 301 redirect chains on Magento
我們已經成功地從HTTP
遷移到HTTPS
,現在有了一些重定向鏈。 我們要直接執行以下操作:
從http://domain.tld到https://www.domain.tld
從http://domain.tld/subdir/到https://www.domain.tld/subdir/
現在,首先將www添加,然后再添加301
到HTTPS
,如下所示:
http://domain.tld => http://www.domain.tld => https://www.domain.tld
http://domain.tld/subdir/ => http://www.domain.tld/subdir/ => https://www.domain.tld/subdir/
另外,如果可能,服務器(Magento存儲)上的所有其他域都不應使用HTTPS,而應僅重定向回HTTPS。
謝謝,
DirectoryIndex index.php
SetEnvIf SERVER_PORT 443 HTTPS=on
SetEnvIf X-Forwarded-Proto https HTTPS=on
<IfModule mod_rewrite.c>
// DEFAULT //
RewriteEngine on
Options +FollowSymLinks
RewriteBase /
DirectoryIndex index.php
// REDIRECT ALL TO HTTPS //
RewriteCond %{HTTP_HOST} www\.domain\.tld [NC]
RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R=301,L]
// REMOVE INDEX.PHP AND REIDIRECT TO ROOT DIRECTORY //
# IN ALL DIRECTORIES (EVEN IN SUB DIRECTORIES)
# RewriteCond %{THE_REQUEST} /index\.php [NC]
# ONLY WHEN ON ROOT
RewriteCond %{THE_REQUEST} \s+/index\.php [NC]
RewriteRule ^(.*?)index\.php$ /$1? [L,R=301,NC,NE]
// REMOVE HOME REWRITE FROM MAGENTO //
RewriteRule ^home/?$ /? [R=301,L,NC]
// ADD WWW TO NONE WWW FOR BOTH HTTPS AND NONE HTTPS //
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
// REDIRECT ALL .HTML FILES AND ALL .HTML/ FILES WITH TRAILING SLASH //
RewriteRule ^google[0-9a-f]+.html$ - [L]
RewriteRule (.+)\.html$ /$1/ [L,R=301]
RewriteRule (.+)\.html\/$ /$1/ [L,R=301]
// ADD TRAILING SLASH //
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ $1/ [L,R=301]
// CHECK IF REDIRECT POINTS TO A VALID FILE ##
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
// REWRITE EVERYTHING ELSE TO INDEX.PHP //
RewriteRule .* index.php [L]
</IfModule>
您可以將http->https
和non-www->www
規則組合在一個301重定向規則中,如下所示:
# // REDIRECT main domain to HTTPS and add www //
RewriteCond %{HTTP_HOST} !^(?!www\.)[^.]+\.domain\.tld$ [NC]
RewriteCond %{HTTP_HOST} ^domain\.tld$ [NC,OR]
RewriteCond %{HTTPS} off
RewriteRule ^ https://www.domain.tld%{REQUEST_URI} [R=301,L,NE]
# redirect sub domains to non http
RewriteCond %{HTTP_HOST} ^(?!www\.)[^.]+\.domain\.tld$ [NC]
RewriteCond %{HTTPS} on
RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.