Apache 2.2 – How to Redirect Root via .htaccess

.htaccessapache-2.2redirect

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

example:

mysite.com/1 redirects to somewhere
mysite.com/admin opens a page

i want mysite.com/ to redirect to mysecondsite.com and only this with a 301 redirect using htaccess

Best Answer

Try this:

RewriteEngine on
RewriteCond %{HTTP_HOST} mysite\.com [NC]
RewriteCond %{REQUEST_URI} ^/$
Rewriterule ^(.*)$ http://mysecondsite.com/ [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.