本文介绍了的.htaccess改写$ _ GET变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下页面:
mysite/news/index.php?tag=tag&name=name&id=id
我想重写这一点,以便它去那种如下:
mysite/news/tag/name-id
这方面的一个完整的例子是。
foobar/news/apple/the-new-iphone-5-9001
另外经过我重写这个URL将我仍然能够获取数据,我通常会如:
$ _ GET ['标签'] //将苹果 $ _GET ['名称'] //将是全新的,与iPhone 5 $ _GET ['身份证'] //将9001解决方案
添加这在Web根为.htaccess。
RewriteEngine叙述上 的RewriteBase / 重写规则^新闻/([^ /] +)/(+?) - (\ d +)/ $ /news/index.php?tag=$1&name=$2&id=$3I have the following page:
mysite/news/index.php?tag=tag&name=name&id=idI want to rewrite this so that it goes kind of as follows
mysite/news/tag/name-idA full example of this would be.
foobar/news/apple/the-new-iphone-5-9001Also after I rewrite this URL will I still be able to pull data as I would normally for instance:
$_GET['tag'] //would be apple $_GET['name'] //would be the-new-iphone-5 $_GET['id'] //would be 9001解决方案
Add this to .htaccess in your web root.
RewriteEngine On RewriteBase / RewriteRule ^news/([^/]+)/(.+?)-(\d+)/?$ /news/index.php?tag=$1&name=$2&id=$3
更多推荐
的.htaccess改写$
发布评论