0

how can i redirect two domain on the same server.. let say this domains

http://www.game.com -> http://www.games.com
http://game.com -> http://www.games.com
http://games.com -> http://www.games.com (*this is not redirecting*)

all domain all should redirect to this domain http://www.games.com

heres the current htaccess content

RewriteCond %{HTTP_HOST} ^game.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.game.com$
RewriteRule ^/?$ "http\:\/\/www\.games\.com\/" [R=301,L]

RewriteCond %{HTTP_HOST} ^games.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.game.com$
RewriteRule ^/?$ "http\:\/\/www\.games\.com\/" [R=301,L]
David Pashley
  • 23,497
  • 2
  • 46
  • 73

3 Answers3

2

Everyone loves to use mod_rewrite when there's often a much simpler way of doing the same thing. This uses mod_alias.

<VirtualHost *:80>
  ServerName game.com
  ServerAlias www.game.com
  ServerAlias games.com
  Redirect permanent / http://www.games.com
</VirtualHost>
<VirtualHost *:80>
  ServerName www.games.com
  .
  .
  .
</VirtualHost>
David Pashley
  • 23,497
  • 2
  • 46
  • 73
1

mod_rewrite seems overkill. If you have access to the vhost configs, then you can simplify by capturing the Hosts in a single vhost and use RedirectMatch.

<VirtualHost *:80>
    ServerName games.com
    ServerAlias game.com www.game.com

    RedirectMatch permanent .* http://www.games.com/
</VirtualHost>
Dan Carley
  • 25,617
  • 5
  • 53
  • 70
  • i dont have access to vhost configs.. can i do this in htaccess? –  Oct 21 '09 at 10:04
  • This should be doable in htaccess, and redirect is a much better way to do it. – LapTop006 Oct 21 '09 at 10:27
  • 1
    You can use `RedirectMatch` in a directory/`.htaccess` context. But how you apply it will depend very much upon how your vhosts are configured. It would be best to update your question to include them. – Dan Carley Oct 21 '09 at 10:28
0

That last RewriteCond shouldn't be necessary -- it's a duplicate of the second condition in the first rule.

Without seeing your full Apache config I can't say for sure, but the most common cause of this sort of problem in my experience is when the vhost that you've put the rewrite in for doesn't actually cover the hostname, and some other vhost config is being used for the domain.

womble
  • 96,255
  • 29
  • 175
  • 230