【问题标题】:How to redirect subfolder/index.php to subfolder/如何将子文件夹/index.php 重定向到子文件夹/
【发布时间】:2016-05-08 08:42:30
【问题描述】:

希望你能理解我的问题:

我的网站是 html/php,我遇到了一个小问题。

我正在使用 htaccess 作为根 index.php 文件:

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php
RewriteRule ^index\.php$ / [L,R=301]

但我也有子文件夹,例如 www.example.com/sub-folder/ 而且我的子文件夹没有任何 .htaccess 文件

现在,当我访问该网站时,www.example.com/index.php 会重定向到 www.example.com,这非常好,也是我需要的。

但是,当我访问 >> www.example.com/sub-folder/index.php 它应该重定向到 >> www.example.com/sub-folder/

但没有任何效果。请帮忙。

【问题讨论】:

    标签: php apache .htaccess redirect mod-rewrite


    【解决方案1】:

    要将 /subfolder/index.php 重定向到 /subfolder/ ,您可以使用:

    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /subfolder/index\.php
    RewriteRule ^subfolder/index\.php$ /subfolder/ [L,R=301]
    

    【讨论】:

      【解决方案2】:

      您可以使用此通用规则从您网站的任何位置删除index.php

      RewriteEngine On
      
      # remove index.php
      RewriteCond %{THE_REQUEST} /index\.php [NC]
      RewriteRule ^(.*?)index\.php$ /$1 [L,R=302,NC,NE]
      

      【讨论】:

        猜你喜欢
        • 2018-09-30
        • 2012-10-23
        • 2019-04-29
        • 1970-01-01
        • 1970-01-01
        • 2021-09-08
        • 1970-01-01
        • 2017-12-05
        • 2013-10-26
        相关资源
        最近更新 更多