我希望有一个URL http://something.com/somestring,其中somestring由php $ _GET获取,而不是必须使用$ _GET [“var”]编写http://something.com/index.php?var=somestring和php内部。
我该怎么做?
答案 0 :(得分:2)
如果您在Apache上运行,则可以使用mod_rewrite。其他服务器有不同的方法,但通用术语“URL重写”来描述此功能。
答案 1 :(得分:0)
您可以使用.htaccess和mod_rewrite来执行此操作,假设您使用apache作为webserver - > http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html
答案 2 :(得分:0)
查看.htaccess和mod_rewrite。
答案 3 :(得分:0)
您的问题已经得到解答。但是为了给你一个案例的常见例子:
RewriteEngine
RewriteCond ./%{REQUEST_URI} !-f
RewriteRule ^(\w+)$ index.php?var=$1 [L]
第一个cond阻止规则将请求重写为真实文件。第二个采用任何字母数字字符串,并将其作为GET参数附加到您的脚本中。
答案 4 :(得分:0)
另一个选择是使用$_SERVER["QUERY_STRING"]
http://something.com/index.php?=somestring
$_SERVER["QUERY_STRING"]
将返回“ somestring”