Reputation: 81
I read another post on SO but it didn't work for me... I would like to access from https://VALUE.example.com - what is currently available at https://example.com/folder/VALUE/
I tried:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [OR]
RewriteCond %{HTTP_HOST} ^.example\.com$
RewriteRule ^folder/([^/]+)/?$ https://$1.example.com/ [NC,R=301,L]
but it didn't work... any idea?
I took this as reference: Rewrite folder to subdomain
Upvotes: 0
Views: 34
Reputation: 1982
I have redefined your code a little bit:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC]
RewriteRule ^/?folder/([^/]+)(/.*)?$ https://$1.example.com/ [R=301,NC,L]
In your second line there wad on .
to much, so example.com
(without the www.) could not work. Than you can combine both RewriteCond
lines in one. Last but not least, if the original URL have something additional e.g. https://example.com/folder/VALUE/something-here
than it could also not work.
One additional remark: The whole thing would only work if on your server mod_rewrite is enabled and you are allowed to use htaccess files (with mod_rewrite), this is not always the case.
Upvotes: 1