简体   繁体   English

.htaccess 重写 $_GET 变量

[英].htaccess rewriting $_GET variables

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:此外,在我重写此 URL 之后,我仍然可以像往常一样提取数据,例如:

$_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.将此添加到 web 根目录中的 .htaccess 中。

RewriteEngine On
RewriteBase /

RewriteRule ^news/([^/]+)/(.+?)-(\d+)/?$ /news/index.php?tag=$1&name=$2&id=$3

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM