Jimmy Adaro Jimmy Adaro - 15 days ago 6
PHP Question

mod_rewrite issue with GET parameter

I'm modifying the Apache

.htaccess
file for rewrite products' URL, so I can go from this

domain.com/section/products/product.php?url=some-product-name


to this

domain.com/section/products/some-product-name


Here's the
mod_rewrite
code that I'm using:

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

RewriteRule ^section/products/(.*)$ /section/products/product.php?url=$1 [QSA,L]


It just returns a 500 server error.

What could be the issue?

Answer

It is because your rewrite rules are infinitely looping. Which is due to the fact section/products/(.*) pattern matches original and rewritten URI.

You can use this to fix it:

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

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