【问题标题】:How to add two index.php file in .htaccess file for Codeigniter如何在 Codeigniter 的 .htaccess 文件中添加两个 index.php 文件
【发布时间】:2016-12-03 04:57:44
【问题描述】:

我在 WWW 中有两个应用程序,我为两个应用程序 app1 和 app2 创建了两个索引文件 id1.php 和 id2.php

结构

www\app1\application...
www\app2\application..
www\system\

id1.php 和 id2.php 的位置

www\app1\id1.php
www\app2\id2.php

我已经创建了 .htaccess 如下

RewriteEngine on
RewriteCond $1 !^(id1|id2\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ app1/id1.php 

这样我可以打开应用程序app1,localhost\app1\welcome,但是我无法打开localhost\app2\welcome,

如何在 .htaccess 中添加 id2.php?

【问题讨论】:

  • 文件app2\welcome是否存在?或者app1/* 应该由app1/id1.php 服务,app2/* 应该由app2/id2.php 服务?

标签: php apache .htaccess codeigniter mod-rewrite


【解决方案1】:

假设 app1app2 应该在您的公共 URL 中,并且与您在 Web 根目录中的物理目录相匹配,请不要为他们在你的根.htaccess。他们每个人的目录中都应该有自己的.htaccess。确保每个都有正确的基础,例如RewriteBase /app1/。确保不干扰以这些目录开头的 URL,方法是在根目录中不进行重写或显式忽略它们。

/.htaccess

RewriteEngine on
RewriteBase /

# always match app dirs and do nothing, so allow their own rewriting
RewriteRule ^(?:app1|app2)(?:$|/) - [L]

# any non-app rules go here

/app1/.htaccess

RewriteEngine on
RewriteBase /app1/
# files
RewriteCond $0 !^(?:index\.php|robots\.txt)$
# directories
RewriteCond $0 !^(?:resources|some-other-dir)(?:$|/)
RewriteCond %{REQUEST_FILENAME} !-f
# do you really need to exclude dirs? are you allowing auto-index pages?
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .+ index.php [NS,L,DPI]

【讨论】:

    猜你喜欢
    • 2017-10-31
    • 1970-01-01
    • 1970-01-01
    • 2013-03-07
    • 2013-10-01
    • 2013-11-03
    • 1970-01-01
    • 2014-08-24
    • 1970-01-01
    相关资源
    最近更新 更多