: Problem getting rewrite from subdomain to directory to work I want to redirect demo.example.com to example.com/my-demo. This is my rewrite rule, but I'm not getting it to work on my production
I want to redirect demo.example.com to example.com/my-demo. This is my rewrite rule, but I'm not getting it to work on my production server:
RewriteCond %{HTTP_HOST} ^demo.example.com
RewriteRule ^(.*)$ /my-demo/ [R=301,L]
More posts by @Lee4591628
4 Comments
Sorted by latest first Latest Oldest Best
put this in .htaccess file in you're demo.example.com directory:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^demo.example.com [NC]
RewriteRule (.*) example.com/demo/ [L,R=301]
i.e: demo.example.com is in folder root-folder/demo
put that .htaccess file on folder demo, not on root-folder.
hope this work for you.
As it stands, you are redirecting to the same host. ie. demo.example.com/file is redirecting to demo.example.com/my-demo/file, not example.com/my-demo/file, which is going to result in a redirect loop. You need to specify an absolute URL in the RewriteRule substitution:
RewriteEngine On
RewriteCond %{HTTP_HOST} =demo.example.com
RewriteRule ^(.*)$ example.com/my-demo/ [R=301,L]
If it's not a ServerAlias but a subdomain, remember to put your .htacces file in the subdomain, not in the main domain directory. Also add "RewriteEngine On" in .htaccess if you did not yet.
Do you have an ServerAlias demo.example.com for the VirtualHost that has this RewriteRule? If you don't, that is the reason it doesn't work.
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.