Manikiran
Manikiran

Reputation: 1

htaccess rewrite url with multiple parameters in a sub folder

I need to rewrite the following url:

 http://localhost/homemarket/products/C1/C2/

to

http://localhost/homemarket/products.php?catergory=C1&sub_category=C2

I tried searching all over stackoverflow, and found similar rewrite rules but I am facing the following problems:

Here's what I have tried:

# Do not remove this line, otherwise mod_rewrite rules will stop working
Options +MultiViews
RewriteEngine On
RewriteBase /

#Prevent viewing of .htaccess file
<Files .htaccess>
order allow,deny
deny from all
</Files>

#Prevent directory listings
Options All -Indexes

#Error Documents
ErrorDocument 404 /homemarket/error.php?404
ErrorDocument 500 /homemarket/error.php?500

#Remove extensions
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ /homemarket/buyers/$1.php [NC,L]
RewriteRule ^products/([^/]*)/([^/]*)/?$ /homemarket/buyers/products.php?category=$1&sub_category=$2 [NC,L]

DirectoryIndex index.php

Upvotes: 2

Views: 1155

Answers (1)

Amit Verma
Amit Verma

Reputation: 41219

Your first rule matches both uris, You need to exclude the slash in your rule so that it can not conflict with other rules :

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/.]+)$ /homemarket/buyers/$1.php [NC,L]

Upvotes: 1

Related Questions