[英]basic URL Rewriting in php issue
我的网页上有网址,例如:
www.abc.com/product_list.php?id=12&pId=1&gpId=0
我希望它显示为:
www.abc.com/product_list.php/12/1/0
我知道这是一个非常基本的问题,但是我是php新手。
您的帮助将不胜感激。
我做了这样的实验,但无法正常工作:(在我的htaccess文件中,通过谷歌搜索)
RewriteRule ^product_list.php /product_list.php/id=$1/pId=$2/gpId=$3 [NC]
我的.htaccess文件:
RewriteEngine On
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule ^ - [L]
RewriteCond %{HTTP_USER_AGENT} (google|yahoo|msn|aol|bing) [OR]
RewriteCond %{HTTP_REFERER} (google|yahoo|msn|aol|bing)
RewriteRule ^([^/]*)/$ hamper-anastassia.php?$1 [L]
RewriteRule index.html$ /index.php
RewriteRule about.html$ /about.php
RewriteRule products.html$ /products.php
RewriteRule partners.html$ /partners.php
RewriteRule career.html$ /career.php
RewriteRule contact.html$ /contact.php
RewriteRule products_(.*)_(.*).html$ products.php?id=$2 [L]
RewriteRule ^product_list/([0-9]+)/([0-9]+)/([0-9]+)/?$ /product_list.php?id=$1&pId=$2&gpId=$3 [NC]
您应该删除.php
捕获第一个参数的简单示例。
RewriteRule ^products/([0-9]+)/?$ show_a_product.php?product_id=$1
更多内容https://www.addedbytes.com/articles/for-beginners/url-rewriting-for-beginners/
基本上每对括号都包含一个变量,这就是$1
, $2
, $3
来源。
RewriteRule ^product_list.php/([0-9]+)/([0-9]+)/([0-9]+)/?$ /product_list.php?id=$1&pId=$2&gpId=$3 [NC]
正如Geoffrey所提到的,您可以更进一步,消除对.php
的需求,但这取决于您,例如:
RewriteRule ^product_list/([0-9]+)/([0-9]+)/([0-9]+)/?$ /product_list.php?id=$1&pId=$2&gpId=$3 [NC]
表示您可以访问/product_list/12/1/0
请删除/注释您的.htaccess文件中的所有内容,然后仅键入这两个语句
RewriteEngine on
RewriteRule ^products/([0-9]+)/([0-9]+)/([0-9]+)/?$ products.php?id=$1&pid=$2&gpid=$3
您的网址应如下所示:
/products/1/2/3
如果仍然出错,请检查您的mod_rewrite配置
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.