【问题标题】:clean url dynamic get parameterclean url 动态获取参数
【发布时间】:2016-04-23 11:33:04
【问题描述】:

您好,我已经创建了干净的网址 但我希望这个干净的网址获得动态网址

例子

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 未找到

帮帮我谢谢

【问题讨论】:

标签: php .htaccess


【解决方案1】:

你可以试试这样的:

<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试试你的配置

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-12-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-22
    • 2018-05-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多