使用mod_rewrite,xampp和windows进行CodeIgniter配置

问题描述:

我是CodeIgniter的noob,正试图弄清楚我正在构建的应用程序的配置。我的设置有问题。使用mod_rewrite,xampp和windows进行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 /主/配置/ config.php文件

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

APP_NAME /主/配置/ 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)。这令人沮丧。

成功!

我终于设法让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] 

RewriteBase/

在你的.htaccess应该

RewriteBase /app_name/ 

指定是哪个目录..

+0

这并没有帮助...相同的行为。 – 2009-12-03 02:16:39

+0

我把mod_rewrite.c改成了mod_rewrite.so,现在我得到了找不到对象的错误信息。当我尝试访问http:// localhost/app_name/welcome/ 时,我还应该声明,app_name目录是与apache根目录不同的驱动器的别名。 Apache的根目录:C:\ XAMPP \ htdocs中\ APP_NAME:d:\项目\ APP_NAME \研发\ 别名是: 别名/ APP_NAME “d:/项目/应用程序名称/发展” 选项指标的FollowSymLinks ExecCGI 设置AllowOverride所有 订购允许,拒绝 所有 – 2009-12-03 22:50:30

首先一个问题。是您的$system_folder变量确实设置为:

$system_folder = "@codeigniter"; 

或者是从怪异的nerf了(我)方式,以便使用降价?如果是,请删除@。它是目录/文件名称的无效字符。

接下来,我相信应该RewriteBase/,因为你使用了Apache的别名,但不可以引用我这句话。

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

您是否已启用mod_rewriteCheck the forum post here

+0

感谢迈克允许,我试图将其改名为“CI”,而不是,我得到了@codeigniter从另一个教程。仍然没有工作。我在想这是我的机器,所以我想尝试为我的个人网站创建一个,看看是否是这样。 – 2009-12-05 17:39:23

如果您在本地机器上使用XAMPP,您应该使用internal而非mod_rewrite

它会加载您的网页下的别名。

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