CodeIgniter:Xampp上的Mod_Rewrite

时间:2012-07-18 20:49:02

标签: codeigniter codeigniter-url php

在试图找出如何让mod_rewrite在xampp中工作3天之后,我终于尝试了CodeIgniter论坛。但即便他们也无法给我我需要的答案。 我在CI论坛上的原始帖子可以在这里找到:http://codeigniter.com/forums/viewthread/221002/

问题是,我确信我已经做了一切以启用mod_rewrite:

在apache / config / httpd.conf中: 取消注释启用mod_rewrite模块的一行。 用“AllowOverride All”替换每一行“AllowOverride None”。

在CI / application / config / config.php中:

  • $ config ['base_url'] ='';
  • $ config ['index_page'] ='';
  • $ config ['uri_protocol'] ='REQUEST_URI';

在CI / application / config / routes.php中:

  • $ route ['default_controller'] =“user”;

我的.htaccess文件位于可以找到应用程序文件夹的同一文件夹中。 .htaccess文件如下所示:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /localhost/Tong-Il/

#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]
php_flag short_open_tag off
php_flag magic_quotes_gpc Off
</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>  

我的网站叫做Tong-Il,所以当我浏览/ localhost / Tong-Il /时,我得到了我的主页,所有内容都很好(单独的页眉,页脚和菜单视图+连接到数据库)。但是当我点击主页上任何地方的链接时,我都会收到404错误!

我点击的任何链接都将由“用户”控制器处理。因此,当我在菜单中按“galery”时,我会使用此url获取404错误页面:localhost / Tong-Il / user / images。 当我将其更改为localhost / Tong-Il / index.php / user / images时,它工作正常! 我的网站可以在网上找到,但我刚刚上传了。一切都在网上工作(包括mod_rewrite),但只是为了给你一个想法:www.tong-il-neeroeteren.be

那里有没有人可以帮我解决这个问题?

1 个答案:

答案 0 :(得分:1)

您在本地设置了RewriteBase错误。而不是

RewriteBase /localhost/Tong-Il/

应该是

RewriteBase /Tong-Il/