【问题标题】:Redirecting folder to another folder avoiding other .htaccess rules将文件夹重定向到另一个文件夹,避免其他 .htaccess 规则
【发布时间】:2014-08-27 19:53:21
【问题描述】:

我的网站的根文件夹包含现有网站。我开发了一个基于 codeigniter 的管理系统,我希望将它发布在 /editor 文件夹中,但是我所做的所有 mod_rewriting 似乎都是徒劳的,因为如果有任何重写,它就无法访问输入字符串或 index.php 文件出现。这是结构:

/
    /editor
        index.php
        .htaccess
    index.php
    .htaccess

这是我当前位于站点根目录的 .htaccess 文件:

DirectoryIndex index.php

RewriteEngine On

RewriteRule  %{REQUEST_URI}^/?editor/(.*)$ (.*)/editor/$1 [R,L]

RewriteCond $1 ^$
RewriteRule ^(.*)$ ?p=homepage [L]

RewriteCond $1 !^(index\.php|editor|css|pdf|eshot|js|fonts|images)
RewriteRule ^(.*)$ index.php/?p=$1 [L]

编辑

当您导航到 /editor 子文件夹时,当前规则显示根 index.php 文件,而它应该显示 /editor 文件夹中的 index.php 文件。

重新编辑

可能是 /editor 子文件夹中的 .htaccess 文件,代码如下:

DirectoryIndex index.php

RewriteEngine on
RewriteCond $1 !^(index\.php|lib|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]

【问题讨论】:

    标签: php apache .htaccess codeigniter mod-rewrite


    【解决方案1】:

    好,我们一步一步来看看。

    首先让我们取消这条规则,因为它在右侧使用正则表达式,因此不合语法:

    RewriteRule  %{REQUEST_URI}^/?editor/(.*)$ (.*)/editor/$1 [R,L]
    

    第二条规则可以简化为:

    RewriteRule ^/?$ ?p=homepage [L]
    

    第三条规则可以改写如下:

    RewriteRule ^(?!(?:index\.php|editor|css|pdf|eshot|js|fonts|images))([^/.]+)/?$ index.php?p=$1 [L]
    

    总而言之,在我看来,您可以像这样精简您的规则:

    DirectoryIndex index.php
    RewriteEngine On
    RewriteRule ^/?$ ?p=homepage [L]
    RewriteRule ^(?!(?:index\.php|editor|css|pdf|eshot|js|fonts|images))([^/.]+)/?$ index.php?p=$1 [L]
    

    【讨论】:

    • 您好,我想我的解释可能有点晦涩,请查看我的编辑以进行澄清:)
    • 不幸的是,这不起作用。也许是另一个文件夹中的 .htaccess 文件?我会在我的问题中发布。
    • 我也错过了一个?在第二个 htaccess 文件中,这意味着您上次的编辑工作:)
    猜你喜欢
    • 2015-03-18
    • 2014-04-03
    • 1970-01-01
    • 1970-01-01
    • 2013-02-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-27
    • 2016-12-21
    相关资源
    最近更新 更多