![](/img/trans.png)
[英]Redirect all non-www, www, http:// requests to https://www. using .htaccess file
[英]Redirect all non-www to www for both http and https with .htaccess
我想將所有非www重定向到www - 如果請求是通過http它應該重定向到http://www.domain.com ,如果請求是通過https然后直接到https://www.domain.com
我在.htaccess中嘗試了以下內容,但它將所有內容重定向到https
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
我已經使用了這個代碼,它完美地解析了。 請檢查一下是否正確。
RewriteEngine On
RewriteBase /
#Redirect non-www to www
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
# Redirect to HTTPS
RewriteCond %{HTTPS} off
RewriteRule (.*) https://www.pnrstatusbuzz.in/%{REQUEST_URI}
您可以將此規則用作第一條規則 :
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTPS}s on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.