Maestro Vladimir
Maestro Vladimir

Reputation: 1196

clean url dynamic get parameter

Hello i already create clean url but i want this clean url get dynamic url

example

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

then using paging if more than 10 data

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

or user can filters only weight or only category or both

example

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

using paging

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

how to technique clean url like this in .htaccess file ?

<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>

i already try link like this

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

this result 404 notfound

Help me thank's

Upvotes: 1

Views: 287

Answers (1)

Florian Lemaitre
Florian Lemaitre

Reputation: 5748

You can try something like this:

<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>

Examples:

#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

You can try your configuration with this online tool

Upvotes: 3

Related Questions