Sign up ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

I want to redirect to 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/$1 [R=301,L]
share|improve this question

4 Answers 4

As it stands, you are redirecting to the same host. ie. is redirecting to, not, 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}
RewriteRule ^(.*)$$1 [R=301,L]
share|improve this answer

Do you have an ServerAlias for the VirtualHost that has this RewriteRule? If you don't, that is the reason it doesn't work.

share|improve this answer

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.

share|improve this answer
It depends on the way one has configured the subdomain. The same effect can be achieved with both a ServerAlias and separate VirtualHost for the subdomain. – Tero Kilkanen Jul 4 '14 at 10:39

put this in .htaccess file in you're directory:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^demo\.example\.com [NC]
RewriteRule (.*)$1 [L,R=301]

i.e: is in folder root-folder/demo
put that .htaccess file on folder demo, not on root-folder.

hope this work for you.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.