SubZeroFX
SubZeroFX

Reputation: 490

Apache redirect 301 based on domain

I've changed links on website a little bit so it's more SEO friendly for our international sites, so I simply translated word "game" and links are now like:

domain.com/games/id-123
domain.pl/gry/id-123
domain.de/spiele/id-123

Previously website links were like:

domain.com/games/id-123
domain.pl/games/id-123
domain.de/games/id-123

Now I want to make apache 301 redirect so links from other websites, google, etc will be redirect to new addressses:

domain.pl/games/id-123 -> domain.pl/gry/id-123
domain.de/games/id-123 -> domain.de/spiele/id-123

I need to add that of course "id-123" is and id of a game, so its "dynamic" and I can't make simple redirect like "Redirect 301 /gry/ domain.com/spiele/".

Upvotes: 1

Views: 495

Answers (1)

Michael Berkowski
Michael Berkowski

Reputation: 270617

Use mod_rewrite and %{HTTP_HOST} to match the appropriate domain in a RewriteCond, and route accordingly:

RewriteEngine On
# Domain ends with .pl
RewriteCond %{HTTP_HOST} \.pl$ [NC]
RewriteRule ^games/(.*)$ gry/$1 [L,R=301]

# Domain ends with .de
RewriteCond %{HTTP_HOST} \.de$ [NC]
RewriteRule ^games/(.*)$ spiele/$1 [L,R=301]

Upvotes: 2

Related Questions