Forum Moderators: phranque

Message Too Old, No Replies

Forwarding domainZ.com to domainA.com

Domain forwarding using vhosts

         

michaerh

2:46 am on Apr 2, 2009 (gmt 0)

10+ Year Member



Apologies, this question has probably been asked a lot, although searching through the archives, I couldn't the answer I was looking for.

Basically, I have 2 domains. I want to forward domainz.com to domaina.com (my primary domain).

I have a vhost on apache / ubuntu setup like this:

<VirtualHost *:80>
ServerName domainA.com
ServerAlias www.domainA.com
ServerAlias www.domainZ.com
ServerAlias domainA.com
ServerAlias domainZ.com
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(domainA.com¦domainZ.com) [NC]
RewriteRule ^(.*)$ [domainA.com...] [R=301,L]

RewriteCond %{HTTP_HOST} ^(www.domainZ.com) [NC]
RewriteRule ^(.*)$ [domainA.com...] [R=301,L]

DocumentRoot /home/somefolder/here/public

</VirtualHost>

A little lost on this as I am a noob to apache... thanks for any help. Feel free to point me to other threads if you have them bookmarked!

michaerh

3:21 am on Apr 2, 2009 (gmt 0)

10+ Year Member



Further research dug this up: [webmasterworld.com...]

Could you use vhost like this:

<VirtualHost *:80>
ServerName domainA.com
ServerAlias www.domainA.com
ServerAlias www.domainZ.com
ServerAlias domainA.com
ServerAlias domainZ.com
RewriteEngine On
RewriteCond %{HTTP_HOST} !^(www\.domainA\.com)?$
RewriteRule (.*) [domainA.com...] [R=301,L]

DocumentRoot /home/somefolder/here/public

</VirtualHost>

?

whoisgregg

3:42 am on Apr 2, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to WebmasterWorld, michaerh!

You'll want to wrap the Rewrite* statements in a <Directory> block [httpd.apache.org]. Other than that, it should work. If you try but get a server error, just be prepared to roll back the changes.

I almost always put rewrites in .htaccess files, so I can't recall off hand if the syntax changes when you put them in httpd.conf. If you have a problem, post back and I know we will be able to help. :)

michaerh

4:06 am on Apr 2, 2009 (gmt 0)

10+ Year Member



Hi whoisgregg, thanks for replying! I have made adjustments like so:

<VirtualHost *:80>
ServerName domainA.com
ServerAlias www.domainA.com
ServerAlias www.domainZ.com
ServerAlias domainA.com
ServerAlias domainZ.com
<Directory /home/somefolder/here/public>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(domainA.com¦domainZ.com) [NC]
RewriteRule ^(.*)$ [domainA.com...] [R=301,L]

RewriteCond %{HTTP_HOST} ^(www.domainZ.com) [NC]
RewriteRule ^(.*)$ [domainA.com...] [R=301,L]
<Directory>

DocumentRoot /home/somefolder/here/public

</VirtualHost>

But it is still not working. I also should point out that I am editting this in /etc/apache2/sites-available (Using Apache 2) not directly in the httpd.conf.

Still trying to figure out Apache's process here too..

Do I need to add a CNAME too?

jdMorgan

6:31 am on Apr 2, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Replace two rules with one, by making the "www." optional:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(domainA\.com¦[b](www\.)?[/b]domainZ\.com) [NC]
RewriteRule [b]^/([/b].*)$ http://www.domainA.com/$1 [R=301,L]

Note that the Rule pattern has been changed to start with a slash. This is one of the differences between code in a config file versus code in an .htaccess file.

Restart your server and flush your browser cache after any change to the code.

Replace the broken pipe "¦" characters with solid pipe characters before use; Posting on this forum modifies the pipe characters.

Jim

michaerh

1:29 pm on Apr 2, 2009 (gmt 0)

10+ Year Member



Awesome thanks to both of you for your help! The other part I needed to complete was create a zone for domainZ.com through slicehost's DNS admin tool. For those in a similar boat, you can just duplicate domainA.com. Hope this helps anyone stuck.

Topic - Closed.