2

I have these rulesets which are working.

RewriteCond %{HTTPS} =on
RewriteCond %{HTTP_HOST} ^www\.example\.city$ [NC]
RewriteRule ^(.*)$ https://example.city/$1 [R=301,L]

RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^(www\.)?example\.city$ [NC]
RewriteRule ^(.*)$ https://example.city%{REQUEST_URI} [R=301,L,QSA]

I have a certificate that will work with any number of subdomains. I can map subdomains onto subdirectories in cpanel. But I will eventually have many of these. How can I have a generic rule in .htaccess to map a subdomain to the same named subdirectory ?

For example

https://plumber.example.city

to

https://example.city/plumber

After reading and trying to follow Appache docs I came up with this, but it fails to redirect. It also takes a bit long so I think it may be looping

RewriteCond %{HTTP_HOST} ^(.*)\.example\.city$ [NC]
RewriteRule ^(.*)$ https://example.city/%1 [L,QSA]

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.