Europeuser Europeuser - 1 year ago 112
PHP Question

.htaccess to load index in dynamic folder name

I am having problem with .htaccess to load index in dynamic folder name.
Here is my directory structure:

root/products/ -> this is constant folder name

instead of using GET for product urls:


I want to put the product url after products folder and to look like:


My .htaccess file is in products folder and has this code:

RewriteBase /products/
RewriteRule ^index\.php$ - [L,NC]
RewriteRule . index.php [L]

but it doesn't work.
It actually loads the index file but in the console I can see it is looding js file over 1000 times if I don't stop the page.. It looks like is reloading the page so many times and adds I suppose timestamp at the end of the js file like:


Can you help me please and show me what is wrong? thanks !

Answer Source

Inside /products/.htaccess you can use these rules:

RewriteEngine On
RewriteBase /products/

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

RewriteRule ^([^/]+)/?$ index.php?product=$1 [L,QSA]

RewriteRule ^[^/]+/([^/]+)/?$ index.php?product=$1 [L,QSA]
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download