PHP $ _GET和.htaccess重写 [英] PHP $_GET and .htaccess rewrite
问题描述
我知道这可能是一个常见的问题,并已被问过,但.htacess看起来陌生的我,我似乎无法得到这个从看previous问题的工作。
I know this is probably a common question and has been asked before but .htacess looks foreign to me and I can't seem to get this to work from looking at previous questions.
我有一个指数脚本搜索和语法是:
I have a index script that searches and the syntax is:
.../listing/?field=property_type&query=retail
我只是想改写这个来:
I simply want to rewrite this to:
.../listing/{field}/{query}
另外一个抓,我有一些领域是布尔值。例如:
One other catch, I have some fields that are boolean.. for example:
.../listings/?forlease=1
因此,在这种情况下,我只是使用 isset()函数
但想改写这个来:
.../listings/forlease/
感谢您的帮助一如既往!堆栈溢出石头!
Thanks for your help as always! Stack Overflow rocks!
我看到一些很好的答案,但我完全看什么:
I see some good answers but completely what I'm looking for:
用户请求: ... /上市/房产类型/零售/
阿帕奇重写为: ../上市/场=房产类型及放大器;查询=零售
脚本认为: $ _ GET ['场'] ='房产类型'
&放大器; $ GET ['查询'] ='零售'
在布尔的情况下(所有的布尔将只有一个导演):
In the case of the boolean (all booleans will have only one Dir):
用户请求: ... /上市/ forlease /
阿帕奇重写为: ../上市/ forlease = 1
脚本认为: $ _ GET ['forlease'] = 1
推荐答案
在你的.htaccess,你可以有几个简单的规则:
In your .htaccess you can have a couple of simple rules:
RewriteRule ^.*/listings/([a-zA-Z0-9_]+)/([a-zA-z0-9_]+)$ /listing/?property_type=$1&query=$2 [QSA,L]
RewriteRule ^.*/listings/forlease/$ /listing/?forlease=1 [QSA,L]
这篇关于PHP $ _GET和.htaccess重写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!