簡體   English   中英

將主URL重定向到HTTPS,將所有子域重定向到HTTP,但保留現有規則

[英]Redirect Main URL to HTTPS, All Subdomains to HTTP but keep existing rules

目前正在處理某些東西,需要我的htaccess文件的幫助。

我現在已經設置好它,並且按我想要的方式工作,它將刪除結尾的斜杠,並刪除.php,因此它看起來像一個目錄。 它還會將bar.example.com重定向到文件example.com/thing?foo=bar

我想使用我購買的SSL證書並在任何主域頁面上強制使用HTTPS,但是在訪問子域時強制使用HTTPS,因為我的證書不是通配符。

感謝您的幫助,以下是我目前所擁有的信息。

RewriteEngine on
Options +FollowSymLinks

RewriteCond %{HTTP_HOST} !^www\.example.com
RewriteCond %{HTTP_HOST} ^(.+).example.com
RewriteRule ^([^/]*)$ http://example.com/thing?foo=%1 [P,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/$ http://example.com/$1 [R=301,L]
RewriteRule ^([^/.]+)$ $1.php [L]

將您現有的條件直接重定向到https://,然后添加一個新的規則來檢查%{HTTPS} 有關更多信息,請參見Apache文檔

RewriteEngine on
Options +FollowSymLinks

RewriteCond %{HTTP_HOST} !^www\.example.com
RewriteCond %{HTTP_HOST} ^(.+).example.com
# CHANGE: Redirect your subdomains directly to the secure target URL
RewriteRule ^([^/]*)$ https://example.com/thing?foo=%1 [P,L]

RewriteCond %{REQUEST_FILENAME} !-d
# CHANGE: same goes for the folders
RewriteRule ^([^/]+)/$ https://example.com/$1 [R=301,L]
RewriteRule ^([^/.]+)$ $1.php [L]

# NEW: Redirect everything else that comes in on `http://www.`
RewriteCond %{HTTP_HOST} ^www\.example.com
RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://www.example.com/$1 [R=301,L]

暫無
暫無

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

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