Jimmy Adaro Jimmy Adaro - 10 months ago 54
PHP Question

mod_rewrite with previous rule affecting other rule

I have the next

for being able of access to


from the folder called
. The original URL looks like this:


This is that rule:

RewriteRule ^section/products/(.*)$ section/_products/$1 [L,NC]

Now I need to rewrite this URL:


To this one:


I'm trying with this:

Options -Indexes
Options +FollowSymlinks
Options -MultiViews
RewriteEngine on
RewriteBase /

RewriteRule ^section/products/(.*)$ section/_products/$1 [L,NC]

RewriteRule ^(section/products/brand)/([\w-]+)$ /section/_products/brand/index.php?brand=$1 [QSA,L,NC]

Also with this:

RewriteRule ^(section/products/brand)/([\w-]+)$ /section/products/brand/index.php?brand=$1 [QSA,L,NC]

None of those two are working for me.

Should the
rule go after or before the other rule?
I can't find the right logic.

Answer Source

You can have it like this:

Options +FollowSymlinks -Indexes -MultiViews
RewriteEngine on
RewriteBase /

# skip all files and directories from rewrite rules below
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]

RewriteRule ^(section/products/brand)/([^/]+)$ $1/index.php?brand=$2 [QSA,L,NC]

RewriteRule ^(section)/products/(.*)$ $1/_products/$1 [L,NC,QSA]