HTAccess mod rewrite issue using QSA

倾然丶 夕夏残阳落幕 提交于 2019-12-24 04:22:01

问题


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


回答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.



来源:https://stackoverflow.com/questions/2575850/htaccess-mod-rewrite-issue-using-qsa

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!