【问题标题】:.htaccess in subfolder.htaccess 在子文件夹中
【发布时间】:2011-08-23 12:55:30
【问题描述】:

主站点使用 .htaccess 运行 WordPress

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

我将在子目录site.com/online/ 中创建一个 CodeIgniter 应用程序 如果只是在子文件夹中添加 CI .hta 文件,它将不起作用。 CI .htaccess:

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

是否可以合并两个 .htaccess 文件或在 CI 子文件夹中使用 .htaccess 做一些事情? 谢谢。

UPD。 感谢您的回答,我尝试了所有变体,最终将项目移至子域。

【问题讨论】:

    标签: php .htaccess codeigniter


    【解决方案1】:

    首先,你的 .htaccess 应该是这样的:

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{THE_REQUEST} !^GET\s/+online/ [NC]
    RewriteRule . /index.php [L]
    </IfModule>
    
    #Then add this for CI handling in the same .htaccess
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond $1 !index\.php [NC]
    RewriteRule ^online/(.*)$ online/index.php?/$1 [L,NC]
    

    然后您可以删除(或重命名)online 子文件夹中的 .htaccess。

    【讨论】:

    • 感谢您的回答。当我添加这个时,如果输入 /online/welcome/,浏览器将返回 404
    • 如果online/welcome/ 是一个有效的目录名称,并且您希望将其作为online/index.php?/online 处理,则需要通过删除条件RewriteCond %{REQUEST_FILENAME} !-d 来放宽上述规则。现在试试,我已经编辑了我的答案。
    • 嗨。浏览器再次重定向到 Not found
    • +1 - 这种方法对我有用(基本上,只需将子目录,在本例中为 online,添加到重写规则中)。
    【解决方案2】:

    对 codeigniter .htaccess 试试这个:

    RewriteEngine on
    RewriteBase /online
    RewriteCond $1 !^(index\.php|robots\.txt|img|styles|js)
    RewriteRule ^(.*)$ /index.php?/$1 [L]
    

    否则对该子文件夹的所有请求都将被重定向到 wordpress。

    【讨论】:

      【解决方案3】:

      你在设置AllowOverride吗?根据docs,您需要允许FileInfo 覆盖mod_rewrite。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-09-14
        • 2014-06-23
        • 2018-02-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多