Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.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!

like image 894
Arerrac Avatar asked Dec 15 '22 23:12

Arerrac


1 Answers

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]
like image 125
anubhava Avatar answered Dec 17 '22 11:12

anubhava