Forum Moderators: phranque
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!
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>
?
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. :)
<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?
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(domainA\.com¦[b](www\.)?[/b]domainZ\.com) [NC]
RewriteRule [b]^/([/b].*)$ http://www.domainA.com/$1 [R=301,L]
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