clean url dynamic get参数

时间:2016-01-18 10:21:31

标签: php .htaccess

您好我已经创建了干净的网址   但我想要这个干净的网址获取动态网址

例如

http://localhost:8081/olshop/products/filters/?weight=1&category=shrit

然后使用分页,如果超过10个数据

http://localhost:8081/olshop/products/filters/?weight=1&category=shrit/1

或用户只能过滤重量或仅过滤类别或两者

例如

http://localhost:8081/olshop/products/filters/?category=shrit

使用分页

http://localhost:8081/olshop/products/filters/?category=shrit/1

如何在.htaccess文件中清理这样的URL?

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule index$                                          index.php [L]
RewriteRule ^products/(\d+)$                                index.php?p=products&page=$1 [L]
RewriteRule ^products/filters/([^/]+)/?$                    index.php?p=products&weight=$1 [L]
RewriteRule ^products/filters/(.*)\/(\d+)$                  index.php?p=products&weight=$1&page=$2 [L]
RewriteRule ^([^/.]+)/?$                                    index.php?p=$1  [QSA,L]
ErrorDocument 404 /404.html             
</IfModule>

我已经尝试过这样的链接

http://localhost:8081/olshop/products/filters/?weight=1&category=shrit

此结果404未发现

帮助我谢谢

1 个答案:

答案 0 :(得分:3)

您可以尝试这样的事情:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /olshop/
RewriteRule index$ index.php [L]
RewriteRule ^products/(\d+)$ index.php?p=products&page=$1 [L]
RewriteRule ^products/filters/([0-9]+)/$ index.php?p=products&page=$1&%{QUERY_STRING} [L]
RewriteRule ^products/filters/?$ index.php?p=products&%{QUERY_STRING} [L]
RewriteRule ^([^/.]+)/?$ index.php?p=$1  [QSA,L]
ErrorDocument 404 /404.html
</IfModule>

示例:

#This url:
http://localhost:8081/olshop/products/filters/1/?weight=1&category=shrit
#is rewrite to:
http://localhost:8081/olshop/index.php?p=products&page=1&weight=1&category=shrit

#This url:
http://localhost:8081/olshop/products/filters/?weight=1&category=shrit
#is rewrite to:
http://localhost:8081/olshop/index.php?p=products&weight=1&category=shrit

您可以使用this online tool

尝试配置