【问题标题】:CodeIgniter configuration with mod_rewrite, xampp and windows带有 mod_rewrite、xampp 和 windows 的 CodeIgniter 配置
【发布时间】:2010-12-22 14:58:45
【问题描述】:

我是 CodeIgniter 的菜鸟,我正在尝试找出我正在构建的应用程序的配置。我的设置有问题。

我在 Windows 上运行 XAMPP,并使用别名目录指向应用程序目录。换句话说:“http://localhost/app_name/”指向应用程序的根目录。在我为 mod_rewrite 执行 .htaccess 之前,这一切似乎都运行良好。然后,每次我尝试使用控制器时,我都会回到 xampp 根目录。

我的配置是:

目录

/app_root
/app_root/codeigniter // where code igniter is located.
/app_root/main        // where the main app is located.  It' the applications 
                      // directory cut from code igniter and renamed.

.htaccess

<IfModule mod_rewrite.**so**>
RewriteEngine On
RewriteBase **/app_name/**
RewriteCond %{REQUEST_URI} ^codeigniter.*
RewriteRule ^(.*)$ /index.php?/$1 [L] 

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>

index.php

$system_folder = "@codeigniter";
$application_folder = "main";

app_name/main/config/config.php

$config['base_url'] = "http://localhost/app_name/";
$config['index_page'] = "";

app_name/main/config/routes.php

$route['default_controller'] = "welcome";

我还应该声明 app_name 目录是与 apache 根目录不同的驱动器的别名。

Apache Root: c:\xampp\htdocs\
App_name: d:\projects\app_name\development\

别名是:

Alias /app_name "d:/projects/app name/development"
<Directory "d:/projects/app name/development">
  Options Indexes FollowSymLinks ExecCGI
  AllowOverride All
  Order allow,deny
  Allow from all
</Directory> 

提前感谢您的帮助...如果您不介意,请在使用代码回答时“解释”您在做什么。我想知道我做错了什么。如果你能帮我解决这个问题,我会给你买啤酒(通过 PayPal)。这令人沮丧。

【问题讨论】:

    标签: php .htaccess codeigniter xampp


    【解决方案1】:
    RewriteBase /
    

    在你的 .htaccess 中应该是

    RewriteBase /app_name/
    

    指定它是哪个目录..

    【讨论】:

    • 这没有帮助...同样的行为。
    • 我将 mod_rewrite.c 更改为 mod_rewrite.so 现在我收到 object not found 错误消息。当我尝试转到localhost/app_name/welcome 时,我还应该声明 app_name 目录是与 apache 根目录不同的驱动器的别名。 Apache Root: c:\xampp\htdocs\ App_name: d:\projects\app_name\development\ 别名为: Alias /app_name "d:/projects/app name/development" Options Indexes FollowSymLinks ExecCGI AllowOverride All Order allow,deny Allow from all
    【解决方案2】:

    首先,一个问题。您的 $system_folder 变量是否真的设置为:

    $system_folder = "@codeigniter";
    

    或者这是一种奇怪的(对我来说)使用降价的方式的 nerf?如果是,请删除@。它是目录/文件名的无效字符。

    接下来,我相信你的 RewriteBase 应该是 /,因为你在 Apache 中使用了别名,但不要引用我的话。

    我个人使用此处提供的 .htaccess 格式:CodeIgniter URLs in the User Guide;在标题删除 index.php 文件下。然而,有很多方法可以做到这一点。 quick Google search 产生几千个。

    您是否启用了mod_rewriteCheck the forum post here.

    【讨论】:

    • 感谢 Mike,我尝试将其重命名为“ci”,我从另一个教程中获得了 @codeigniter。仍然没有工作。我认为这是我的机器,所以我打算尝试为我的个人网站创建一个,看看是不是这样。
    【解决方案3】:

    成功!!

    我终于设法让 URL 重写工作,这是一个多么漫长而艰巨的旅程。这是我最终得到的工作。请注意,RewriteBase 上没有反斜杠。考虑到我读过的内容,非常有趣。感谢所有试图提供帮助的人。

    # Options
    Options -Multiviews
    Options +FollowSymLinks
    
    #Enable mod rewrite
    RewriteEngine On
    #the location of the root of your site
    #if writing for subdirectories, you would enter /subdirectory
    RewriteBase /app_name
    
    #Removes access to CodeIgniter 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]
    
    #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
    
    #This last condition enables access to the images and css
    #folders, and the robots.txt file
    RewriteCond $1 !^(index\.php|images|robots\.txt|css)
    
    RewriteRule ^(.*)$ index.php?/$1 [L]
    

    【讨论】:

      【解决方案4】:

      如果你在本地机器上使用 XAMPP,你应该使用internal 而不是mod_rewrite

      它将以别名加载您的页面。

      我花了一段时间才弄明白——显然你应该在远程服务器上使用mod_rewrite 来实现同样的目的。

      【讨论】:

        猜你喜欢
        • 2010-12-11
        • 2010-11-04
        • 1970-01-01
        • 1970-01-01
        • 2015-07-24
        • 1970-01-01
        • 2013-08-05
        • 2012-08-29
        • 2014-01-26
        相关资源
        最近更新 更多