Url rewriting 使PHP GET参数看起来像目录
我正在努力做到这一点:Url rewriting 使PHP GET参数看起来像目录,url-rewriting,Url Rewriting,我正在努力做到这一点: http://foo.foo/?parameter=value “皈依”为 http://foo.foo/value 谢谢。假设您正在使用Apache,以下教程非常有用: 第二个教程有你的答案。准备深入挖掘一个名为mod_rewrite的地牢。假设您运行的是Apache,那么.htaccess中的代码对我有用: RewriteEngine on RewriteRule ^([a-zA-Z0-9_-]+)/$ /index.php?parameter=$1 根据您的站
http://foo.foo/?parameter=value
“皈依”为
http://foo.foo/value
谢谢。假设您正在使用Apache,以下教程非常有用:
第二个教程有你的答案。准备深入挖掘一个名为
mod_rewrite
的地牢。假设您运行的是Apache,那么.htaccess中的代码对我有用:
RewriteEngine on
RewriteRule ^([a-zA-Z0-9_-]+)/$ /index.php?parameter=$1
根据您的站点结构,您可能需要添加一些规则。如果您使用Apache,请使用mod rewrite规则。这是创建虚拟目录的更好、更安全的方法。在Apache服务器上启用
mod_rewrite
,并使用.htaccess
规则将请求重定向到控制器文件
.htaccess
# Enable rewrites
RewriteEngine On
# The following two lines skip over other HTML/PHP files or resources like CSS, Javascript and image files
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# test.php is our controller file
RewriteRule ^.*$ test.php [L]
test.php
$args = explode('/', $_SERVER['REDIRECT_URL']); // REDIRECT_URL is provided by Apache when a URL has been rewritten
array_shift($args);
$data = array();
for ($i = 0; $i < count($args); $i++) {
$k = $args[$i];
$v = ++$i < count($args) ? $args[$i] : null;
$data[$k]= $v;
}
print_r($data);
Google->.htaccess+mod_重写教程。请指出您的web服务器,因为这是一个web服务器问题,而不是关于PHP的问题。如果您碰巧正在使用IIS,您可以查看此链接以获取信息(因为其他人都在共享mod_rewrite信息)-
Array
(
[abc] => 123
[def] => 456
)