RewriteRule指令重定向到不存在的页面

发布于 2024-12-24 15:46:14 字数 353 浏览 1 评论 0原文

我在 .htaccess 文件中设置指令时遇到问题。试图实现这一点,如果访问者尝试打开

http://localhost/occasions/anniversary/

...它必须调用根目录中的 browser.php 文件,并发送“周年纪念”作为参数之一。

我定义了如下指令:

RewriteRule ^/occasions/(.*)/$ http://localhost/browse.php?page=$1

... 但它返回页面未找到错误。

你能告诉我为什么吗,并帮我解决这个问题。

预先非常感谢您!

I have trouble setting directives in .htaccess file. Trying to achieve that if visitor tries to open

http://localhost/occasions/anniversary/

... it have to call browse.php file in root directory, and to send 'anniversary' as one of the parameters.

I defined directive like:

RewriteRule ^/occasions/(.*)/$ http://localhost/browse.php?page=$1

... but it returns Page not found error.

Can you tell me why, and help me to solve this.

Thank you very much in advance!

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

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

发布评论

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

评论(2

2024-12-31 15:46:14

只需删除 RewriteRule 中的第一个斜杠,如下所示:

RewriteRule ^occasions/(.*)/$ http://localhost/browse.php?page=$1

.htaccess 文件中使用 RewriteRule 时,它​​不会匹配,因为第一个斜杠不会传递用于评估。

Just remove your first slash in your RewriteRule, like this:

RewriteRule ^occasions/(.*)/$ http://localhost/browse.php?page=$1

It won't match when using RewriteRule within .htaccess files, as this first slash isn't passed for evaluation.

倾城花音 2024-12-31 15:46:14

尝试使用 Firefox + TamperData Addon 并检查响应以查看页面重定向而不是 browse.html

https://addons.mozilla.org/en-US/firefox/插件/篡改数据/

Try it with Firefox + TamperData Addon and check the response to see where is the page redirecting instead of browse.html.

https://addons.mozilla.org/en-US/firefox/addon/tamper-data/

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