.htaccess 301 将旧域上的所有页面重定向到新域上的单个页面 [英] .htaccess 301 redirect all pages on old domain to a single page on new domain

查看:34
本文介绍了.htaccess 301 将旧域上的所有页面重定向到新域上的单个页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望将旧域上的每个页面重定向到新域上的单个页面.它还应该重定向 www 和非 www 版本.对域 old.com 的每个请求,无论是什么,都应该指向 www.new.com 根.

I'm looking to redirect each and every page on the old domain to a single page on the new domain. It should also redirect both the www and non-www versions. Every single request to the domain old.com, whatever it may be, should lead to www.new.com root.

old.com/1.php
www.old.com/2.php
old.com/2.php
old.com/links/index.php
old.com/about-us.html
old.com/?string=1

应该全部重定向到:

www.new.com/

www.new.com/

我正在寻找 .htaccess 解决方案.

I'm looking for a .htaccess solution.

推荐答案

可以在old.com vhost中使用RedirectMatch

You can use RedirectMatch in the old.com vhost

RedirectMatch permanent .* http://www.new.com/

Redirect 将匹配 URI 的尾随部分附加到重定向 URI,但使用 RedirectMatch 由您选择要传输的部分(如果有)使用括号和 $number 引用.

Redirect appends the trailing portion of the matched URI to the redirection URI but with RedirectMatch it's up to you to choose the parts (if any) that you want to transfer using parentheses and $number references.

如果旧域和新域必须是磁盘上相同文档根目录的别名,那么您可能必须使用 mod_rewrite

If the old and new domains must be aliases for the same document root on disk then you'll probably have to use mod_rewrite

RewriteEngine on
RewriteCond %{HTTP_HOST} old\.com$
RewriteRule .* http://www.new.com/ [L,R=301]

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

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