Forum Moderators: phranque

Message Too Old, No Replies

Redirect from one domain to specific page of another domain

         

bcowan

6:14 pm on Sep 30, 2009 (gmt 0)

10+ Year Member



I am trying to create a redirect in Apache 2.2 in my Virtual Hosts file from one domain (http://www.newdomain.com) to a specific page on our main domain (http://www.maindomain.com/specificpage.html).

I don't really spend much time with Apache at all, so I really don't know what I am doing (as I am sure you will see):

The following is only redirecting (http://www.newdomain.com) to (http://www.maindomain.com) - not to the specific page. Any help would be much appreciated.

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} !^(www\.newdomain\.com)?$
RewriteRule ^/$ [maindomain.com...] [R=301,L]

Thanks,

jd01

6:25 pm on Sep 30, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Actually, I'm surprised it redirects anything, unless your browser does not send a host header, because your condition says if the domain is NOT www.newdomain.com (designated by the preceding !). I think you want the opposite... If it IS newdomain.com or is NOT maindomain.com (depending on your specific application of the code).

EDITED:
If you would like it to be IS newdomain.com, simply remove the ! from what you have and change it to:
((www)?\.newdomain\.com)

The preceding will make the www optional.

The following should redirect everything:

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} !^(www\.maindomain\.com)?$
RewriteRule .? http://www.maindomain.com/specificpage.html [R=301,L]

.? on the left side says any character 0 or 1 time, so it 'implicitly' matches everything, because it's an un-anchored pattern.