2
我是重写URL的新手。到目前为止,我已经成功地重写了其中的一些,但我无法“捕捉”$_GET
变量,我尝试了所有的东西。这里是我的脚本:如何使用正则表达式从URL获取主键?
$item_name = (isset($_GET["item_name"])) ? $_GET["item_name"] : "";
$item_id = (isset($_GET["item_id"])) ? $_GET["item_id"] : "";
echo $item_name;
echo $item_id;
这里是htaccess文件:
Options +FollowSymlinks
RewriteEngine On
RewriteRule ^categories localhost/folder/folder/categories.php [NC,L]
RewriteRule ^home localhost/folder/index.php [NC,L]
RewriteRule ^pictures localhost/folder/folder/stuff.php [NC,L]
RewriteRule ^account localhost/folder/folder/account.php [NC,L]
RewriteRule ^articles localhost/folder/folder/articles.php [NC,L]
我真正要做的是抓住$_GET["item_name"]
和$_GET["item_id"]
出新的清洁URL localhost/folder/home/guitar/123
的。
这是我必须尝试完成上述,并且不起作用。
RewriteRule ^home/(0-9a-zA-Z]+)$ htaccess/index.php?item_name=$1&item_id=$2 [NC,L]
这给了我一些变量,但不完全是我想要的:
RewriteRule ^(.*)$ index.php?item_name=$1&item_id [L]
Jon Lin我<3你的男人,非常感谢你! – nero 2014-12-02 20:37:07