开发者

.htaccess domain redirect only domain changing need to keep full url intact

开发者 https://www.devze.com 2023-02-13 04:59 出处:网络
So far I have this and it works well. It redirects from: (www.)myoldsite.com/folder1/folder2/ to www.newdomain.com

So far I have this and it works well. It redirects from:

(www.)myoldsite.com/folder1/folder2/

to

www.newdomain.com

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

This works fine if people go to:

(www.)myoldsite.com/folder1/folder2

They get redirected but all folders further down the hierarchy are lost.

I need it to redirect but keep its url structure beyond the domain name. E.g.

(www.)myoldsite.com/folder1/folder2/folder3/folder4/file1.html

-->开发者_Python百科 REDIRECT TO -->

www.newdomain.com/folder3/folder4/file1.html

Thank you in advance.


Try this:

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

Additionally I've merged the two RewriteConds into one.

0

精彩评论

暂无评论...
验证码 换一张
取 消