簡體   English   中英

如何將 https://www 重定向到 https:// 和 http://www 到 https:// 和 http:// 到 https://

[英]How to redirect https://www to https:// and http://www to https:// and http:// to https://

我需要重定向以下所有地址:

  • http://www.example.com
  • https://www.example.com
  • http://example.com

使用 .htaccess 文件中的永久重定向到https://example.com

我會嘗試以下方法:

RewriteEngine On

# URL with www rewrite to https without www
RewriteCond %{HTTP_HOST} ^(www\.)(.*) [NC]
RewriteRule (.*) https://%2%{REQUEST_URI} [L,R=301]

# URL without www rewrite to https
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^(www\.)(.*) [NC]
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM