.htaccess:将所有请求转发到另一个站点

发布于 2024-09-06 04:16:53 字数 334 浏览 7 评论 0原文

我必须将现有网站转发到另一个网站。

我想将旧网站上的每个请求转发到新网站的根目录。

示例:
http://oldsite.tld/index.php?mode=foo&action=bar 应转发到 http://newsite.tld/不转发 http://newsite.tld/index.php?mode=foo&action=bar

单独使用 .htaccess 可以吗?我也有可能使用 PHP。

谢谢。

I have to forward an existing website to another one.

I want to forward each and every request on the old site to the root of the new site.

Example:
http://oldsite.tld/index.php?mode=foo&action=bar should be forwarded to http://newsite.tld/ and not http://newsite.tld/index.php?mode=foo&action=bar.

Is this possible with .htaccess alone? I'd also have the possibility of using PHP.

Thanks.

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

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

发布评论

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

评论(2

触ぅ动初心 2024-09-13 04:16:53

好吧,我决定使用 mod_rewrite 来实现,.htaccess 中的一个简单的Redirect 并不能完全完成这项工作。

以下是我最终使用的内容:

RewriteRule (.*) http://newsite.tld/? [R=301,L]

URL 末尾的 ? 确保忽略所有查询。

Okay, I decided to do it with mod_rewrite, a simple Redirect in the .htaccess didn't quite do the job.

Here's what I ended up using:

RewriteRule (.*) http://newsite.tld/? [R=301,L]

The ? at the end of the URL makes sure all queries are ignored.

青衫负雪 2024-09-13 04:16:53

只需在每个文件的顶部放置

<?php
    header('Location: http://newsite.tld');
?>

对所有 .php 文件运行快速前置操作。

Simply on the top of every file put

<?php
    header('Location: http://newsite.tld');
?>

Run a quick prepend operation on all .php files.

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