如何将default.php重定向到/

发布于 2024-10-01 06:44:45 字数 280 浏览 0 评论 0原文

我正在尝试使用 .htaccess 将 default.php 重定向到 Apache 中的 / (不带参数的路径),但到目前为止我还没有找到一种方法来完成这项工作。如果我执行以下操作:

Redirect permanent /default.php powerkaraoke.com/

我会收到 500 错误。其他重定向工作正常,例如 powerkaraoke.com->www.powerkaraoke.com。

这样做的正确方法是什么?预先感谢您的任何帮助。

I am trying to redirect default.php to / (path with no arguments) in Apache with .htaccess, but so far I have not find a way to make this work. If I do something like:

Redirect permanent /default.php powerkaraoke.com/

I get 500 error. Other redirects work fine, for example powerkaraoke.com->www.powerkaraoke.com.

What is the proper way of doing this? Thanks in advance for any help.

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

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

发布评论

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

评论(2

梦断已成空 2024-10-08 06:44:45
RewriteEngine on
RewriteRule ^default.php$ / [R=301,L] 

我认为这应该有效。

RewriteEngine on
RewriteRule ^default.php$ / [R=301,L] 

I think that should work.

闻呓 2024-10-08 06:44:45

重定向 需要绝对路径或绝对网址:

新 URL 应该是以方案和主机名开头的绝对 URL,但也可以使用以斜杠开头的 URL 路径,在这种情况下,当前服务器的方案和主机名将添加。

但你提供的只是一个相对路径。所以试试这个:

Redirect permanent /default.php /

但是 Redirect 只是匹配给定的路径前缀并添加剩余的路径段(例如 /default.php/foo/bar 被重定向到 /foo /bar),您可能需要使用 RedirectMatch 相反:

RedirectMatch permanent ^/default\.php$ /

Redirect requires an absolute path or absolute URL:

The new URL should be an absolute URL beginning with a scheme and hostname, but a URL-path beginning with a slash may also be used, in which case the scheme and hostname of the current server will be added.

But what you’ve provided is just a relative path. So try this:

Redirect permanent /default.php /

But as Redirect just matches the given path prefix and adds remaining path segments (e.g. /default.php/foo/bar gets redirected to /foo/bar), you might want to use RedirectMatch instead:

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