使用SO的URL格式$ _GET [英] Use SO's URL format for $_GET
问题描述
如何获得 http://www.site.com/sections/tutorials/tutorial1
,例如,在地址栏中保持这样的状态,但将它转换为 $ _ GET
PHP的请求以解决?
我可以使用一个 .htaccess
文件,但我不希望URL被重写 - 我希望它保持干净和友好。是我唯一的选择在这里使用PHP的字符串分裂函数来获取一些假装 $ _ GET
数据?
谢谢, / p>
James
> .htaccess 来分割URL,URL不会改变,而是用index.php指向各种 $ _ GET
变量,
#在$ b $上重写改写
$ b $上的RewriteEngine b#按此顺序获取变量,[object],[object,action],[object,action,selection]
RewriteRule ^([^ / \。] +)/?$ /index.php?object = $ 1 [L,NC,QSA]
RewriteRule ^([^ / \。] +)/([^ / \。] +)/?$ /index.php?object=$1&action = $ 2 [L,NC,QSA]
RewriteRule ^([^ / \。] +)/([^ / \。] +)/([^ / \。] +)/?$ /index.php?object=$1&action=$2&selection=$3 [L,NC,QSA]
StackOverflow has a very neat, clean URL format. It looks the same as a directory structure, but there can't be a directory for each question on here! My question is this:
How can I get http://www.site.com/sections/tutorials/tutorial1
, for example, to stay like that in the address bar, but convert it to a $_GET
request for PHP to mess around with?
I could use a .htaccess
file, but I don't want the URL being rewritten - I'd like it to remain clean and friendly. Is my only option here to use PHP's string splitting functions to get some pretend $_GET
data?
Thanks,
James
What about this, using .htaccess
to split the URL up, the URL won't change but instead point to index.php with various $_GET
variables, this could could be increased to cover more URL sections.
# turn rewriting on
RewriteEngine on
# get variables in this order, [object], [object,action], [object,action,selection]
RewriteRule ^([^/\.]+)/?$ /index.php?object=$1 [L,NC,QSA]
RewriteRule ^([^/\.]+)/([^/\.]+)/?$ /index.php?object=$1&action=$2 [L,NC,QSA]
RewriteRule ^([^/\.]+)/([^/\.]+)/([^/\.]+)/?$ /index.php?object=$1&action=$2&selection=$3 [L,NC,QSA]
这篇关于使用SO的URL格式$ _GET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!