【问题标题】:.htaccess rewriting $_GET variables.htaccess 重写 $_GET 变量
【发布时间】:2011-07-14 12:15:21
【问题描述】:

我有以下页面:

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['tag'] //would be apple
$_GET['name'] //would be the-new-iphone-5
$_GET['id'] //would be 9001

【问题讨论】:

    标签: php regex .htaccess mod-rewrite


    【解决方案1】:

    将此添加到您的网络根目录中的 .htaccess。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-11-10
      • 2015-06-30
      • 1970-01-01
      • 2011-05-16
      • 2011-07-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多