.htaccess以在动态文件夹名称中加载索引 [英] .htaccess to load index in dynamic folder name

查看:70
本文介绍了.htaccess以在动态文件夹名称中加载索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用.htaccess加载动态文件夹名称中的索引时遇到问题。
这是我的目录结构:

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

,而不是对商品网址使用GET:

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

我的.htaccess文件位于products文件夹中,具有以下代码:

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

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

,但是它不起作用。
它实际上加载了索引文件,但是在控制台中,如果我不停止页面,我可以看到它正在淹没js文件超过1000次。看起来好像重新加载了页面很多次并添加了我的时间戳js文件的末尾,例如:

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 !

推荐答案

/products/.htaccess 内部,您可以使用这些规则:

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]

这篇关于.htaccess以在动态文件夹名称中加载索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆