1

我不想将我的 CI 分成多个应用程序。我应该说它位于根目录 /var/www/app/ 上名为 app 的文件夹中。首先我尝试了这个设置:

/system/
/application/
  /app1/
  /app2/
app1.php
app2.php
.htaccess

但我无法让我的 htaccess 正确指向。因此我继续这样做:

/system/
/app1/
  .htaccess
  /application/
  index.php
/app2/
  .htaccess
  /application/
  index.php

现在它适用于 url:mysite.com/app/app1/index.php/welcome - 但我想从 URL 中隐藏 index.php。因此我的 .htaccess 看起来像这样:

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

但是它不起作用,我在尝试访问 mysite.com/app/app1/welcome 时收到 404。有人可以澄清我的.htaccess 有什么问题吗?我在根目录上有另一个 .htaccess 并将从那里运行一些 wordpress,但它会影响我运行 CI 的 /app 文件夹吗?非常感谢!

4

3 回答 3

3

尝试在每个文件夹中添加这个(来自http://codeigniter.com/wiki/mod_rewrite):

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    #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> 
于 2012-06-21T10:06:35.073 回答
0

添加 RewriteBase 指令后它是否有效?

RewriteEngine on
RewriteBase /app1/
RewriteCond $1 !^(index\.php|gfx|css|js|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
于 2012-06-21T10:00:34.250 回答
0

好的,现在它正在工作。经过几个小时的调试。我不确定到底是什么技巧,但我认为我的AllowOverride All默认虚拟主机中缺少一个。在 apache 重新启动并且每个 /app/app1/ 文件夹中的这个 htaccess 之后它开始工作:

RewriteEngine on

RewriteCond $1 !^(index\.php|gfx|css|app|js|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]

感谢所有为我的问题做出贡献的人。

于 2012-06-21T11:39:32.773 回答