Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Which redirect rule would I use to redirect all pages under olddomain.example to be redirected to newdomain.example?

The site has a totally different structure, so I want every page under the old domain to be redirected to the new domain index page.

I thought this would do (under olddomain.example base directory):

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

But if I navigate to olddomain.example/somepage I get redirected to newdomain.example/somepage. I am expecting a redirect only to newdomain.example without the page suffix.

How do I keep the last part out?

Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
853 views
Welcome To Ask or Share your Answers For Others

1 Answer

The below answer could potentially cause an infinite redirect loop...

Here, this one redirects everything after the domain name on the URL to the exact same copy on the new domain URL:

RewriteEngine on 
RewriteRule ^(.*)$ http://www.newdomain.com/$1 [R=301,L]
www.example.net/somepage.html?var=foo

redirects to:

www.newdomain.com/somepage.html?var=foo

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...