[英]redirect all non-www to www, all http to https, and exclude subdomains
我正在嘗試重定向
example.com 到www.example.com和http://example.come to https://www.example.com
但是,如果用戶輸入
admin.example.com, http://admin.example.com or https://admin.example.com
不應重定向到www.admin.example.com
我可以為此使用什么 .htaccess?
您可以在站點根目錄 .htaccess 中使用此規則:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [NC,OR]
RewriteCond %{HTTPS} !on
RewriteCond %{HTTP_HOST} ^(?:www\.)?([^.]+\.[^.]+)$ [NC]
RewriteRule ^ https://www.%1%{REQUEST_URI} [R=301,L,NE]
正則表達式(?:www\\.)?([^.]+\\.[^.]+)
將匹配example.com
或www.example.com
但不匹配admin.example.com
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.