2

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?

1 Answer 1

1

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]
Sign up to request clarification or add additional context in comments.

6 Comments

This is genius. Thank you very much. I need help with other mod_rewrite thing, and I can't make another question in 90 mins, can I ask for your help here in the comments?
Thanks. I have this folder called "products" in this path: /section/products/. I also have the product echoer file (products.php), and I want to be able of differentiate between products and products/, so if the URL hasn't the slash should go to products.php. If the URL has the slash (without anything else passed as get) must redirect to /section/products (the .php file). I hope I explained that correctly.
Yes it is. Inside /section/ I have /section/products.php and /section/products/.
products.php is loaded from /section/, product.php is loaded from /section/products/ and /section/products/ doesn't have a index.php file inside.
Is there any way to "simulate" the /section/products? Example, changing the name of the real folder to something like the_products and then re-direct it to /section/products.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.