的.htaccess改写$ _ GET变量 [英] .htaccess rewriting $_GET variables

查看:124
本文介绍了的.htaccess改写$ _ GET变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下页面:

  mysite.com/news/index.php?tag=tag&name=name&id=id
 

我想重写这一点,以便它去那种如下:

  mysite.com/news/tag/name-id
 

这方面的一个完整的例子是。

  foobar.com/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=$3
 

I have the following page:

mysite.com/news/index.php?tag=tag&name=name&id=id

I want to rewrite this so that it goes kind of as follows

mysite.com/news/tag/name-id

A full example of this would be.

foobar.com/news/apple/the-new-iphone-5-9001

Also 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改写$ _ GET变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆