Question

RewriteCond %{REQUEST_URI} (.*)Products/(.*) [NC]
RewriteRule .* Products/viewproduct.php?category_name=%2 [L]

I am trying to Get category name but it shows viewproduct.php

Was it helpful?

Solution

You can use this rule:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule Products/(.+)$ Products/viewproduct.php?category_name=$1 [L,NC,QSA]

Problem is that your rule is executing twice. 1st time for /Products/abc/ and 2nd time for `/Products/viewProduct.php/ URL since your pattern is matching both times. RewriteCond above will stop this behavior.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top