2016-04-28 126 views
1

的.htaccess帮助我什么原始地址样子:需要URL重写传递参数之后,已经重写URL

localhost/aoc/product.php?pid=2&cname=australia 

应用的.htaccess:

Options +FollowSymlinks 

RewriteEngine On 

RewriteBase /aoc 

RewriteRule ^product-category/([A-Za-z0-9_\-]+)/([A-Za-z0-9_\-]+).html product.php?pid=$1&cname=$2 

结果网址:

localhost/aoc/product-category/1/australia.html 

但我面临的问题是如何通过参数来排序页面项目。例如,让我想通过变量?sort=xxx&sort=xxx.如何通过编辑htaccess以最佳方式实现?

localhost/aoc/product-category/1/australia.html?sort=xxx - Not working 
localhost/aoc/product-category/1/australia.html&sort=xxx - Not working 

我不想看起来丑陋低于但编辑htaccess的作品后组合:

http://localhost/aoc/product-category/1/xxx/australia.html 

http://localhost/aoc/product-category/1/australia.html/xxx/ 

请帮我解释它。

回答

0

要结合新老查询字符串,使用QSA(查询字符串附加)标志

Options +FollowSymlinks 

RewriteEngine On 

RewriteBase /aoc 

RewriteRule ^product-category/([A-Za-z0-9_\-]+)/([A-Za-z0-9_\-]+).html product.php?pid=$1&cname=$2 [QSA] 
+1

哇!这简直太棒了,并且精确地回答了我的问题。谢谢@starkeen的伟大答案。 – WebzinSamir