我想在我的 htaccess 文件中创建重定向。从带有 index.php 的 url 到没有 index.php 的页面,但仅针对一个特定文件夹“catalog”。
例如:
从 /catalog/some_folder/index.php
到 /catalog/some_folder/
或
从 /catalog/some_folder/etc/index.php
到 /catalog/some_folder/etc/
像这样的 URL /catalog2/some_folder/index.php
不必重定向
我尝试添加这些行(本地主机,因为它是 xampp):
RewriteCond %{REQUEST_URI} /catalog/+[^\.]+index.php$
RewriteRule ^index\.php$ localhost/$1 [R=301,L]
但这没有用。我怎样才能强制它正常工作?
最佳答案
您可以在 root .htaccess 中使用此规则:
# remove index.php
RewriteCond %{THE_REQUEST} /index\.php [NC]
RewriteRule ^(catalog/.+)index\.php$ /$1 [L,R=302,NC,NE]
关于php - htaccess 从 index.php 重定向到/仅在特定文件夹中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37514303/