使用 QSA 的 HTAccess mod 重写问题

发布于 2024-08-27 20:18:37 字数 413 浏览 4 评论 0原文

我想向 URL 添加参数,但目前它没有显示在 $_GET 全局中。 我的 htaccess 文件中的片段如下:

RewriteRule ^account/blogs/([0-9]+)/([^\s?]+)/?$ /account/blog.php?blogId=$1 [L,QSA]

然后在我的 php 代码中我想添加一个链接,例如:

/account/blogs/1/ThisIsWhereTheTitleGoes?delete=1

通配符(除空格外的任何字符)选项用于博客标题,因为我永远不知道它会是什么。我知道要在末尾添加一个查询字符串参数,例如 ?delete=1。然而我不希望这是重写的一部分。

有谁知道如何做到这一点? 谢谢

I want to add a parameter to a URL but currently it isnt showing in the $_GET global.
A snippet from my htaccess file is as below:

RewriteRule ^account/blogs/([0-9]+)/([^\s?]+)/?$ /account/blog.php?blogId=$1 [L,QSA]

Then in my php code i want to add a link such as:

/account/blogs/1/ThisIsWhereTheTitleGoes?delete=1

The wildcard (any char but space) option is for the blog title as i never know what it would be. I know want to add a query string param on the end such as ?delete=1. I however dont want this as part of the rewrite.

Does anybody know how to so this?
Thanks

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

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

发布评论

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

评论(1

妖妓 2024-09-03 20:18:37

我最好的选择是简单地将 get 变量添加到正则表达式中,如下所示:

RewriteRule ^account/blogs/([0-9]+)/([^\s?]+)/?(\?(.*))?$ /account/blog.php?blogId=$1&$4 [L,QSA]

这将重写

/account/blogs/1/ThisIsWhereTheTitleGoes?delete=1

/account/blog.php?blogId=1&delete=1

它也将支持其他变量。

My best bet would be to simply add get variables to the regex, like so:

RewriteRule ^account/blogs/([0-9]+)/([^\s?]+)/?(\?(.*))?$ /account/blog.php?blogId=$1&$4 [L,QSA]

This would rewrite

/account/blogs/1/ThisIsWhereTheTitleGoes?delete=1

to

/account/blog.php?blogId=1&delete=1

It would also support additional variables.

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