Crayl
Crayl

Reputation: 1911

Strange behavior of htaccess redirect

My goal is to redirect an entire domain to another. Every URL of the old domain shall redirect to the root URL of the new domain.

To achieve this I'am doing:

redirect 301 / http://www.google.de/

Problem is that when I test it on http://localhost/randomPath then it redirects to http://www.google.de/randomPath, but not to the root URL of google.de.

Does anyone know how to solve this?

Upvotes: 2

Views: 41

Answers (1)

anubhava
anubhava

Reputation: 785008

Use mod_rewrite for finer control on rules like matching Host name etc.:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^(www\.)?olddomain\.com$ [NC]
RewriteRule ^ http://www.google.de/? [L,R]

? in the end of target URI will strip off any existing query string.

Upvotes: 2

Related Questions