Reputation: 31
I have this .htaccess rule
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]
This covers the parent domain but not the subdomain.
My subdomain has the same public folder as of parent domain.
example.com is redirected to https://example.com
But subdomain.example.com is not redirected to https://subdomain.example.com
As I said above that both points to same public folder so I want the above rule to handle both.
But I don't want to write my domain or subdomain name in htaccess rule. It shall cover any domain and any subdomain
Upvotes: 0
Views: 108
Reputation: 133
just copy and paste this code:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Upvotes: 0
Reputation:
You can do this with the HTTP_HOST
header:
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R]
So you get it from the request rather than using the server name for the virtual host. Also simplifying the regex since you’re not using the capture.
Upvotes: 1