【发布时间】:2013-04-19 15:48:57
【问题描述】:
我的尝试:
RewriteCond %{QUERY_STRING} ^id=(.*)$ [NC]
RewriteRule ^/product$ /product/%1 [NC,L,R=301]
我只想将此规则应用于/product/ 和/supplier/ 目录。它们都是一级子目录。
注意:product/?id={xxx} 实际上是 product/index.php?id={xxx}。 Apache 隐藏了我的扩展和索引。只是想指出这一点。
我的product/index.php 处理给定的参数并确定它应该显示的页面:
index.php
if ( isset( $_GET['id'] ) && !empty( $_GET['id'] ) ) {
//html for individual page e.g. /product/?id=foo
//e.g. <h1><?= $_GET['id'] ?> Page</h1>
} else {
//html for product list e.g. /product/ (no parameters)
}
【问题讨论】:
-
您尝试在哪里,在一个 .htaccess 文件中?
-
是的,位于根目录中。
标签: .htaccess mod-rewrite