将通配符子域重定向到https

时间:2018-05-12 20:18:38

标签: php .htaccess ssl mod-rewrite

我想将所有通配符子域重定向到https并制作如下的重写规则:

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

我有这段代码,但它没有用,而且我对语法不确定。

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]

1 个答案:

答案 0 :(得分:1)

哟可以用一个RewriteRule

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