php - .htaccess 在动态文件夹名称中加载索引

标签 php apache .htaccess

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

root/products/ -> this is constant folder name

而不是对产品 URL 使用 GET:

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

我想将产品 url 放在产品文件夹之后,看起来像:

root/products/my-product-url

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

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

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

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

你能帮我看看哪里出了问题吗?谢谢!

最佳答案

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

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]

关于php - .htaccess 在动态文件夹名称中加载索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37609306/

相关文章:

apache - ProxyPass 和 ProxyPassReverse 可以在 htaccess 中工作吗?

django - 我把 "WSGIPassAuthorization On"放在哪里?

regex - .htaccess 强制重定向 htaccess 中重写的 url 以使用 https ssl

php - 检查 htaccess 中的 Zend 注册表变量?

apache - 如何使用 HTACCESS 阻止对特定子域的所有访问(定义的 IP 除外)

html - 在非根位置部署的绝对路径

javascript - 在数组中存储具有不同 id 的多个值 - php、javascript

php - 将少量代码应用于域中的每个页面

javascript - 添加按钮以在 Chumper 数据表行中触发引导模式

php - 没有从php post请求中获取参数