W
W
wfg2018-05-16 15:16:20
htaccess
wfg, 2018-05-16 15:16:20

How to implement dynamic subdomains for https only?

How to implement redirect from http to https and use mod_rewrite rule for https only? Works separately.
This type of redirect:

http://demo.example.com => https://demo.example.com

And keep the modrewrite rule like this:
https://demo.example.com => https://example.com/index.php?id=demo

There is this htaccess, but it does not solve the problem.
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]

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Viktor Taran, 2018-05-28
@shambler81

1. I've painted a bunch of examples here, you should go.
https://klondike-studio.ru/standards/standartnyy-h...
Also, you forgot to add a condition to the second rule, do not forget that there can be several conds in a row.

RewriteEngine On

RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

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

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question