使用 urlencoded 参数重写 url

发布于 2024-12-28 18:33:29 字数 688 浏览 1 评论 0原文

我发送一个 urlencoded 地址作为名为 fromurl 到我的页面 http://localhost/myapp/admin/login.php

http://localhost/myapp/admin/login.php?fromurl=%2Fmyapp%2Fadmin%2F

我想使用 mod_rewrite 在表单上启用更好的 URL,我对此很满意新到。上面示例的更好的 URL 变体将具有以下形式:

http://localhost/myapp/admin/login/%2Fmyapp%2Fadmin%2F

我已在 .htaccess 中尝试了这一行,但没有工作(无法找到 URL):

RewriteRule ^admin/login/(.*)$ admin/login.php?fromurl=$1

我还有其他 mod_rewrite规则工作。在这种情况下我应该如何编写RewriteRule?

I send an urlencoded address as a GET parameter called fromurl to my page http://localhost/myapp/admin/login.php:

http://localhost/myapp/admin/login.php?fromurl=%2Fmyapp%2Fadmin%2F

I would like to enable a nicer URL on the form using mod_rewrite which I am quite new to. The nicer URL variant of the example above would have the form:

http://localhost/myapp/admin/login/%2Fmyapp%2Fadmin%2F

I have tried this line in .htaccess which did not work (the URL can not be found):

RewriteRule ^admin/login/(.*)$ admin/login.php?fromurl=$1

I have other mod_rewrite rules working. How should I write the RewriteRule in this case?

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

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

发布评论

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

评论(1

泛滥成性 2025-01-04 18:33:29

尝试转义斜杠:

RewriteRule ^admin\/login\/(.*)$ admin/login.php?fromurl=$1

此外,您可能需要添加重写库(在重写规则之前),因为您没有通过专用主机名访问它

RewriteBase /myapp/

Try escaping your slashes:

RewriteRule ^admin\/login\/(.*)$ admin/login.php?fromurl=$1

Additionally, you might need to add a rewritebase (before the rewrite rule) because you aren't accessing this via a dedicated hostname

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