CodeIgniter mod_rewrite 给出 404 错误 [英] CodeIgniter mod_rewrite gives 404 error

查看:46
本文介绍了CodeIgniter mod_rewrite 给出 404 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个 CodeIgniter 应用程序,我想使用 mod_rewrite 来清理我的 URL.我已经在 htdocs/ci-intro/

I have written a CodeIgniter application and I want to use mod_rewrite to clean up my URL's. I have installed the CodeIgniter application in htdocs/ci-intro/

这是我的 .htaccess 文件:

Here is my .htaccess file:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /ci_intro/

#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> 

我将 CodeIgniter 中的 config.php 更改为以下内容:

I altered the config.php in CodeIgniter to the following:

$config['base_url'] = '';
$config['index_page'] = '';

每当我使用我的链接转到关于页面时,我都会收到来自 CodeIgniter 的 404 消息.我的浏览器中的 URL 似乎已被清理"(index.php 已删除).这是网址:

Whenever I use my links to go to the about page I get a 404 message from CodeIgniter. The URL in my browser seems to be 'cleaned up' though (index.php is removed). This is the URL:

'http://localhost:8888/ci_intro/about'

'http://localhost:8888/ci_intro/about'

有人能帮我摆脱 404 错误并实际将使用定向到关于页面吗?

Can anybody help me getting rid of the 404 error and actually directing the use to the about page?

操作系统:MAC OS X 10.8.2(最新)
服务器软件:MAMP
PHP:5.2.17
浏览器:Chrome &Safari(两个浏览器都会出现这个问题)

OS: MAC OS X 10.8.2 (latest)
SERVER SOFTWARE: MAMP
PHP: 5.2.17
BROWSERS: Chrome & Safari (In both browsers this problem occurs)

推荐答案

试试这个...

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /Your_folder_Name/index.php?/$1 [L]

RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /Your_folder_Name/index.php?/$1 [L]

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

这篇关于CodeIgniter mod_rewrite 给出 404 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆