【问题标题】:.htaccess Redirect to script in subdirectory.htaccess 重定向到子目录中的脚本
【发布时间】:2010-10-05 23:33:25
【问题描述】:

我需要将 .htaccess 重写规则重定向到子目录根目录中的脚本,但仅适用于该子目录中的任何文件/目录...

/
/subdir/
   /index.php
   /somedir/
   /anotherdir/

对于上面的结构,我希望任何浏览到 /subdir 的人都去 /subdir/index.php,任何人去 /subdir/somedir/ 到 /subdir/index.php 等等...

但是,如果它们转到根目录。他们应该留在那里......我已经尝试将一个 .htaccess 文件放在 /subdir 中,并尝试了一堆重写规则,但到目前为止没有任何工作。

更新:我不是说/somedir/需要重定向到index.php,而是/subdir/的任何子目录> 需要重定向...脚本也是,但显然不是 /subdir/index.php

对不起,我之前不清楚。

【问题讨论】:

    标签: .htaccess redirect subdirectory


    【解决方案1】:

    如果我理解你的问题,唯一需要发生的实际重定向是如果有人去 /subdir/somedir(将他们重定向回 index.php

    如果是这样,这应该可以,放入 /.htaccess:

    redirect /subdir/somedir/ /subdir/
    

    【讨论】:

      【解决方案2】:

      如果您只想要一个内部重定向,试试这个mod_rewrite 示例:

      RewriteEngine on
      RewriteCond %{REQUEST_URI} !^/subdir/somedir/index\.php
      RewriteRule ^subdir/somedir/ subdir/index.php [L]
      

      对于外部重定向,只需添加 R 标志(带有可选的重定向状态代码:R=xxx;默认值:302):

      RewriteRule … [L,R=xxx]
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-02-19
        • 1970-01-01
        • 1970-01-01
        • 2015-10-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多