php - 子文件夹中的 .htaccess

标签 php .htaccess codeigniter

主站点使用 .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 做些什么? 谢谢。

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

最佳答案

首先,您的 .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。

关于php - 子文件夹中的 .htaccess,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5968573/

相关文章:

wordpress - htaccess 将domain2.com重定向到domain1.com/specific-page的 final方法

php - 整数相加奇怪的结果

regex - 如何从 url 中删除查询字符串?

.htaccess - 即使目录不存在,也将完整文件路径传递给 php

php - 用于公共(public)类型应用程序的 php 中的 xero api 集成

php - 将 CodeIgniter 语言文件转换为 .po(用于 gettext)

php - 哈希等于的行为不正常

php - 我的 php 代码没有正确添加

php - 仅限于使用 PHP 标记的帖子

php - MYSQL 按日期分组 + 3 小时