简体   繁体   中英

Redirect wildcard subdomains to https

I want to redirect all wildcard subdomains to https and make a rewrite rule like this:

http://#.example.com => https://#.example.com => https://example.com/index.php?id=#

I have this code but it's not working and I'm not sure about the syntax.

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
RewriteCond %{HTTP_HOST} ^(.{2,})\.example.com$
RewriteRule (.*) https://example.com/index.php?id=%1 [P,L]

Yo can do it with one RewriteRule

RewriteEngine on
RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.com$
RewriteRule ^/(.*)$    https://www.example.com/index.php?id=%1 [L,R]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM