Multiple query parameter RESTful URL with .htaccess

穿精又带淫゛_ 提交于 2019-12-06 11:17:25

Here's an .htaccess to capture anything except when files or directories conflict and it routes to /index.php:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

With that we can use /index.php as our request router. In PHP we simply get the request something like so:

<?php
$url_path = $_SERVER['REQUEST_URI'];
// Parse your URL path here...

That said, your URL pattern is non-standard and I'd really recommend against it because proxies and browsers will URL encode the ampersand and equal signs. Let me suggest one of the following instead (and also to use lowercase as it helps with validation of the URL):

http://example.com/products/categories/bags/colours/black
http://example.com/products/category_bags/colours_black
http://example.com/products?category=bags&colours=black
http://example.com/products/categories/bags?colours=black
http://example.com/products/bags?colours=black

To see what will encode in the path of a URL just Google it and look at Google's search URL.

Hope this helps.

-Mike

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!