.htaccess 将所有页面重定向到新域 [英] .htaccess redirect all pages to new domain

查看:31
本文介绍了.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]

这篇关于.htaccess 将所有页面重定向到新域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆