.htaccess 将所有页面重定向到新域

问题描述:

我将使用哪个重定向规则将 olddomain.example 下的所有页面重定向到 newdomain.example?

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.

我认为这样做(在 olddomain.example 基目录下):

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

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

但是如果我导航到 olddomain.example/somepage,我会被重定向到 newdomain.example/somepage.我期望只重定向到 newdomain.example 而没有页面后缀.

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.

如何保留最后一部分?

可能是这样的:

Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^OLDDOMAIN.com$ [NC]
RewriteRule ^(.*)$ http://NEWDOMAIN.com [R=301,L]