Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

htaccess: redirect all requests to different domain (without query arguments)

Tags:

.htaccess

How can I redirect all requests (irrespective of what page is being requested) on sub.domain.com to newdomain.com? Currently I have

Redirect 301 / http://www.newdomain.com/

When a requests comes in for domain.com/shop/product the redirect goes to newdomain.com/shop/product while it should just go to newdomain.com

like image 772
stef Avatar asked Jul 15 '10 13:07

stef


Video Answer


2 Answers

Use Rewrite:

RewriteEngine on
RewriteRule (.*) http://www.newdomain.com/ [R=301,L]
like image 200
Sven Koschnicke Avatar answered Oct 22 '22 04:10

Sven Koschnicke


RewriteCond %{HTTP_HOST} ^(www\.)?olddomain\.com$
RewriteRule (.*) http://www.newdomain.com/$1 [R=301,L]

That will forward any GET requests.

like image 23
AzureMichael Avatar answered Oct 22 '22 03:10

AzureMichael