Link to home
Create AccountLog in
Avatar of snadam
snadam

asked on

How do I use htaccess to redirect the home page, but not other pages

In order to redirect my parked domains to my main domain - example.com - I currently use htaccess as follows:

RewriteCond %{HTTP_HOST} !example.com [NC]
RewriteCond %{HTTP_HOST} !downloads.example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]

I would like example2.com to be redirected to example.com only on the home page, but not on other pages.

How would I go about doing that with htaccess?

Thanks very much,
Adam
Avatar of nemagee
nemagee

Adam,

You can selectively apply rewrite rules by just changing the parameter in a Redirect statement:

     Redirect 301 /old/old.html http://www.you.com/new.html

If the move is permanent, use a 301; if it's temporary, use a 303. In any case, the first relative URL is your local file (the one you want people to hit and then get redirected. The second URL is your destination.

Hope that helps.
Neal
Avatar of snadam

ASKER

Thanks Neal,

I know how to do that, but I don't know how to do it for the home page. Neither of these work:

Redirect / http://www.example.com
Redirect  http://www.example.com
SOLUTION
Avatar of nemagee
nemagee

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of snadam

ASKER

Thanks, I guess my problem is that I'm using Joomla, so I'm having a difficult time figuring out what my home page is. Although there is an index.php file in my root, the following doesn't work:

Redirect 301 index.php http://www.example.com

I was thinking it might be the index.php file in my template, but the following also doesn't work:

Redirect 301 templates/rt_omnicron_j15/index.php http://www.example.com
Oh, okay. I can definitely understand the problem in deciphering that then. Let me ask a colleague who does a fair bit of Joomla development. He should know.
ASKER CERTIFIED SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Also a note on Redirect: the status is optional, the 'page' is a URL and will be matched against the requested URL.

http://httpd.apache.org/docs/2.2/mod/mod_alias.html#redirect
Avatar of snadam

ASKER

Thanks to nemagee trying and for sending me in the right direction and to vdelau for solving my problem.