Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to redirect only my root to another url, but maintain all the /sub/directories where they belong (and redirect)

example: redirects to somewhere opens a page

i want to redirect to and only this with a 301 redirect using htaccess

share|improve this question
up vote 42 down vote accepted

Try this:

RewriteEngine on
RewriteCond %{HTTP_HOST} mysite\.com [NC]
RewriteCond %{REQUEST_URI} ^/$
Rewriterule ^(.*)$ [L,R=301]

If you don't need to check for the old domain (for example, if the directory where your .htaccess is placed is only used by the old domain) you can remove the second line.

share|improve this answer
In my case, I needed to redirect traffic to but not so had to add a regex to line 2: RewriteCond %{HTTP_HOST} ^mysite\.com$ [NC] to ensure the match was for the exact host – jaygooby Jun 23 '14 at 13:18

If you mean you'd only like to redirect "/" to another domain, this will work:

RewriteEngine on
RewriteRule ^$ [R=301,L]

This only matches the domain's root with nothing after it so it will only redirect the domain name without a filename specified.

share|improve this answer

This should work just fine:

RedirectMatch 301 ^/$
share|improve this answer

A shorter solution:

Redirect 301 /
share|improve this answer
This will NOT do what jardel wants. It will redirect ALL pages rather than just the root. – sharoz Jul 16 '13 at 23:49

Your Answer


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