php - htaccess 从 index.php 重定向到/仅在特定文件夹中

标签 php apache .htaccess redirect mod-rewrite

我想在我的 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/

相关文章:

php - CoreDumpDirectory 不适用于 ubuntu;使用 php 获取段错误

.htaccess - 按域阻止引荐来源网址垃圾邮件 - 403 响应有效

apache - 使用 htaccess,仅当 url 包含查询字符串时才允许访问该网站,但允许网站资源(CSS、JS 等)工作?

jquery - 我可以在 .htaccess URL 中使用井号标记吗?

javascript - 通过Ajax访问js发布的外部文件中的id div

php - 我如何获取一个数组,将其除以二并创建两个列表?

php - Laravel Datatable ManyToMany 与多个表的关系

php - 如何捕获PHP中的错误

php - 我怎样才能使一个集合独一无二?

apache - mod_rewrite 'add path info postfix:'