Arerrac
Arerrac

Reputation: 419

.htaccess 301 redirect, keeping paths

I'm trying to redirect www.olddomain.com/content/path to www.newdomain.com/content/path

Somehow:

.htaccess 301 redirect path and all child-paths

RewriteEngine On
RewriteRule ^(.*)$ http://newdomain.com/ [R=301]

Isn't working and is always redirecting to index.

Thanks!

Upvotes: 4

Views: 5702

Answers (2)

Kurt Enget
Kurt Enget

Reputation: 1

anubhava,

What would be the difference between:

RewriteEngine On
RewriteRule ^(.*)$ http://newdomain.com/$1 [L,R=301]

OR you can do:

RewriteEngine On
RewriteRule ^ http://newdomain.com%{REQUEST_URI} [L,R=301]

Upvotes: 0

anubhava
anubhava

Reputation: 785156

Because you're missing captured group $1 in target URL:

RewriteEngine On
RewriteRule ^(.*)$ http://newdomain.com/$1 [L,R=301]

OR you can do:

RewriteEngine On
RewriteRule ^ http://newdomain.com%{REQUEST_URI} [L,R=301]

Upvotes: 13

Related Questions