![](/img/trans.png)
[英]htaccess force https and redirect www to non-www, but no other subdomains
[英]htaccess eliminate www then redirect all non subdomains traffic to https
我已經嘗試了10種不同的配置,所有這些都在這里找到答案,但最終我得到的只是一個重定向循環。
我的最新嘗試如下:
RewriteCond %{HTTP_HOST} ^www.test.com
RewriteRule (.*) http://test.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} !^(.*?)\.test.com$
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
在前兩行中,我消除了www
然后,我正在檢查沒有子域,如果已經設置了https,那么我正在重定向。
最后,我要檢查現有文件等,並通過index.php發送所有流量
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* index.php?%{QUERY_STRING} [L]
誰能發現明顯的錯誤?
此規則將忽略用於http->https
重定向的子域:
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\.test\.com$
RewriteRule ^ https://test.com%{REQUEST_URI} [NE,R=301,L]
PS:這也將取代您的第一個www刪除規則。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.