robosot
robosot

Reputation: 51

htaccess redirect website

I'm trying to redirect all my visitors from the old domain that I use to the new one.

Here is the content of the .htaccess file that I use

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !foobar.com$ [NC]
RewriteRule ^(.*)$ http://foobar.com/$1 [L,R=301]

where http://foobar.com is the new domain.

The code above works but only if the visitor type http://olddomain.com.

What I mean is when the visitor types

http://olddomain.com/terms.php he should be redirected to http://foobar.com/terms.php

I want that whatever the visitor types after the old domain name (like http://olddomain.com/privacy.php, http://olddomain.com/users.php, etc) they go to http://foobar.com/ not to http://foobar.com/privacy.php etc.

Upvotes: 3

Views: 175

Answers (1)

h0tw1r3
h0tw1r3

Reputation: 6818

RewriteEngine On
RewriteCond %{HTTP_HOST} !^foobar\.com$ [NC]
RewriteRule .* http://foobar.com%{REQUEST_URI} [L,R=301]

Upvotes: 3

Related Questions