【问题标题】:CodeIgniter and mod_rewrite with multiple applicationsCodeIgniter 和 mod_rewrite 与多个应用程序
【发布时间】:2012-06-15 20:07:10
【问题描述】:

我正在尝试将 CodeIgniter 用于多个应用程序以及 mod_rewrite 用于应用程序文件夹/名称。

我的CodeIgniter结构如下:

webroot/appone/
webroot/apptwo/
webroot/system/
webroot/index.php
webroot/appone.php
webroot/apptwo.php

我按照此处列出的示例将 CI 与多个应用程序一起使用。 http://codeigniter.com/wiki/Multiple_Applications/

我希望使用 mod_rewrite 来显示以下内容:

domain.com/appone/
domain.com/apptwo/

【问题讨论】:

  • 我不完全确定,但你不应该有两个 .htacess 文件,都在相应的 appone/apptwo 文件夹中吗?
  • 那么我是否需要删除根 appone.php 文件并在加载所有系统文件等的 appone 文件夹中使用 index.php?
  • 我没有测试过它,但它会很有意义,因为您有两个用于不同站点的应用程序文件夹。它们共享相同的核心,但理论上您可能需要完全不同的 htaccess 文件。一定要保留 appone.php 和 apptwo.php 文件,我不能 100% 确定。编辑 @fdias 共享了一个出色的 .htacess 文件,您可以在两个应用程序文件夹中使用。

标签: codeigniter mod-rewrite


【解决方案1】:

我相信德克是正确的。

这是我在每个应用程序文件夹中使用的代码(从 Elliot Haughin 获得),它运行良好。只需将 APP_FOLDER_NAME 更改为您想要的任何 appone、apptwo 等。

在每个文件夹上都有一个 .htaccess 文件,其中包含以下内容:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /APP_FOLDER_NAME

    #Removes access to the system folder by users.
    #Additionally this will allow you to create a System.php controller,
    #previously this would not have been possible.
    #'system' can be replaced if you have renamed your system folder.
    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    #When your application folder isn't in the system folder
    #This snippet prevents user access to the application folder
    #Submitted by: Fabdrol
    #Rename 'application' to your applications folder name.
    RewriteCond %{REQUEST_URI} ^application.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    #Checks to see if the user is attempting to access a valid file,
    #such as an image or css document, if this isn't true it sends the
    #request to index.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
    # If we don't have mod_rewrite installed, all 404's
    # can be sent to index.php, and everything works as normal.
    # Submitted by: ElliotHaughin

    ErrorDocument 404 /index.php
</IfModule> 

PS。不要忘记删除 index.php 并在 CI 配置中定义基本 url。

干杯。

【讨论】:

    猜你喜欢
    • 2012-07-04
    • 1970-01-01
    • 2012-11-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多