如果第一个域有文件夹路径,如何将一个域 301 重定向到另一个域

发布于 2024-07-21 04:21:59 字数 296 浏览 5 评论 0原文

我想要从 www.olddomain.com 进行 301 重定向到 newdomain.com 的根目录,但无论旧域上的文件夹路径是什么,我都希望它能够正常工作。 例如:以下内容都应该重定向到 newdomain.com 的根目录

www.olddomain.com
olddomain.com
www.olddomain.com/folder/file.php
olddomain.com/folder/file.php

我如何使用 .htaccess 文件中的 Mod Rewrite 来做到这一点?

I want to 301 redirect from: www.olddomain.com to the root of newdomain.com but I want it to work no matter what the folder path is on the old domain. eg: the following should all redirect to the root of newdomain.com

www.olddomain.com
olddomain.com
www.olddomain.com/folder/file.php
olddomain.com/folder/file.php

How can I do that with Mod Rewrite in the .htaccess file?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

苍景流年 2024-07-28 04:22:00

尝试以下规则:

RewriteEngine on
RewriteCond %{HTTP_HOST} (^|\.)old\.example\.com$
RewriteRule ^ http://new.example.com/ [L,R=301]

其中 old.example.com 是旧主机名,new.example.com 是新主机名。

Try this rule:

RewriteEngine on
RewriteCond %{HTTP_HOST} (^|\.)old\.example\.com$
RewriteRule ^ http://new.example.com/ [L,R=301]

Where old.example.com is the old host name and new.example.com the new.

北笙凉宸 2024-07-28 04:22:00
<?php
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.newdomain.com/page.html");
exit();
?>

这也应该适合你。

<?php
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.newdomain.com/page.html");
exit();
?>

This should also work for you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文