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

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

都应该重定向到:

should all redirect to:

www.new.com /

www.new.com/

我正在寻找一个解决方案的.htaccess

I'm looking for a .htaccess solution.

推荐答案

您可以在old.com虚拟主机使用RedirectMatch

You can use RedirectMatch in the old.com vhost

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

重定向追加匹配的URI来重定向结尾部分URI,但 RedirectMatch 这是由你来选择您想要使用圆括号来转移部分(如有)及 $号引用。

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天全站免登陆