获取查询字符串中的变量 re_writes
我试图将这四个获取变量(sch、val、lmt、ord)组合成一个漂亮的 url re_write。目前,我的 .htaccess 文件中有以下内容,如果包含所有变量,它就可以工作,但是,如果我只输入前两个变量(sch 和 val),它就会中断:
RewriteRule ^search/([^/]*)/([^/]*)/([^/]*)/([^/]*)$
search.php?sch=$1&val=$2&lmt=$3&ord=$4 [L]
www.domain.com/search/City/London/ 5/上升工程 www.domain.com/search/City/London 但这不是
I am trying to combine these four get variables (sch, val, lmt, ord) into a nice looking url re_write. Currently I have the following in my .htaccess file and it works if all variables are included, however, if I only input the first two variables (sch & val) it breaks:
RewriteRule ^search/([^/]*)/([^/]*)/([^/]*)/([^/]*)$
search.php?sch=$1&val=$2&lmt=$3&ord=$4 [L]
www.domain.com/search/City/London/5/asc works
www.domain.com/search/City/London but this doesn't
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用它来获取整个路径作为文本并解析
www.domain.com/search/City/London/5/asc 工作 www.domain.com/search/City/London 但这不
输出
www.domain.com/search/City/London/5/asc
$paths=city,london,5,asc
www.domain.com/search/City/London
$paths=city,london
您可以使用循环和配对作为密钥/值...如果需要的话
you can use this , to grab whole path as text and parse
www.domain.com/search/City/London/5/asc works www.domain.com/search/City/London but this doesn't
output
www.domain.com/search/City/London/5/asc
$paths=city,london,5,asc
www.domain.com/search/City/London
$paths=city,london
You can use loop and pair as key/value... if needed
为什么不在其前面添加其他重写规则呢? IE:
那应该可行。不确定这是否是您想要的,但我真的认为如果不执行查询并将完整的查询字符串作为一行传递然后在 PHP 端解析它,就“可能”做到这一点。
编辑
与 PHP 相比,在 .htaccess 中执行所有这些操作的好处是它需要更少的逻辑,并且您可以将所需的内容以正确的值传递给脚本。我的偏好是使用上面的 .htaccess。
Why not just add the other rewrite rules ahead of it. IE:
That should work. Not sure if it is what you want, but I do not really think it is "possible" to do that without just doing a query and passing the full query string as one line then parsing it PHP side.
EDIT
The nice thing about doing all this in .htaccess vs PHP is it requires less logic and you pass what you want to your script in the correct values. My preference would be using the .htaccess above.