Linode Forum
Linode Community Forums
 FAQFAQ    SearchSearch    MembersMembers      Register Register 
 LoginLogin [ Anonymous ] 
Post new topic  Reply to topic
Author Message
PostPosted: Tue May 21, 2013 6:01 pm 
Offline

Joined: Tue May 21, 2013 5:48 pm
Posts: 1
Hi All -

I'm running Ubuntu 12.04 and Apache. I have 2 domains setup under VPS on the same linode. I would like domain 1 to redirect to domain 2 using a 301 redirect (so I would rather not use a CNAME). Additionally, I want to make sure both the top-level host and www host redirect to domain 2.

Both domains have been setup on the linode with a VPS. DNS is using linode, and I've setup A records for each pointing to the ip address of my linode. Both domains are currently resolving though domain 1 shows the content for domain 2 (without redirecting). I've verified that mod_rewrite is running.

However, my htaccess file is not having any effect in terms of getting the 301 redirect to work. The htaccess file in the public folder under domain 1.

This is what is in my htaccess file:

#htaccess for domain1.com rewriting to all requests to domains2.com

Code:
#htaccess for domain1.com rewriting to all requests to domains2.com 

RewriteEngine On
Rewritecond %{HTTP_HOST} !^www\.domain2\.com
RewriteRule ^(.*)$ http://www.domain2.com/$1 [R=301,L]


Thanks for your help!


Top
   
PostPosted: Tue May 21, 2013 8:44 pm 
Offline
Senior Member

Joined: Mon Jan 02, 2012 12:45 pm
Posts: 365
If you want domain1 to be redirected to domain2 shouldn't you have:
Code:
# sending domain1 to domain2
Rewritecond %{HTTP_HOST} !^domain1\.com$ [OR]
Rewritecond %{HTTP_HOST} !^www\.domain1\.com$
RewriteRule ^(.*)$ http://www.domain2.com/$1 [R=301,L]


This assumes you have this in the .htaccess file in the root directory of domain1.com


MSJ


Top
   
PostPosted: Tue May 21, 2013 11:27 pm 
Offline
Senior Member

Joined: Mon Aug 31, 2009 2:33 pm
Posts: 78
Location: The OC
A couple things...

Why are you trying to do this in a .htaccess file and not in the virtual host configuration?
What is the AllowOverride directive set to in the the apache2.conf file / virtual host config for domain1.com?
Your .htaccess file includes the dot (.) correct? All mentions in your post above do not have it.


Top
   
PostPosted: Wed May 22, 2013 4:02 pm 
Offline
Sysop

Joined: Sat Nov 27, 2010 3:32 am
Posts: 180
Website: https://blog.timheckman.net/
Location: San Francisco, CA
You can also do this with mod_alias:

Code:
Redirect permanent / http://domain.tld/


Redirects all traffic in that VirtualHost to that URL and adds any URL params and such. You can also do this right inside of the VirtualHost block in your Apache config.

_________________
'If debugging is the process of removing bugs, then programming must be the process of putting them in.' //Edsger Dijkstra
'Nothing is withheld from us which we have conceived to do.' | 'Do things that have never been done.' //Russell Kirsch


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
RSS

Powered by phpBB® Forum Software © phpBB Group