Europeuser
Europeuser

Reputation: 952

.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:

root/products/index.php?product=my-product-url

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

root/products/my-product-url

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:

GET http://www.mysiteexaple.com/js/jalerts/jquery.js?_=1464945951342

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

Upvotes: 3

Views: 1121

Answers (1)

anubhava
anubhava

Reputation: 785196

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]

Upvotes: 2

Related Questions