CodeIgniter mod_rewrite gives 404 error(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 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:CodeIgniter mod_rewrite 给出 404 错误
基础教程推荐
- PHP 守护进程/worker 环境 2022-01-01
- 在 yii2 中迁移时出现异常“找不到驱动程序" 2022-01-01
- 如何在 XAMPP 上启用 mysqli? 2021-01-01
- 使用 PDO 转义列名 2021-01-01
- 找不到类“AppHttpControllersDB",我也无法使用新模型 2022-01-01
- 在 CakePHP 2.0 中使用 Html Helper 时未定义的变量 2021-01-01
- 如何在 Symfony 和 Doctrine 中实现多对多和一对多? 2022-01-01
- phpmyadmin 错误“#1062 - 密钥 1 的重复条目‘1’" 2022-01-01
- HTTP 与 FTP 上传 2021-01-01
- Doctrine 2 - 在多对多关系中记录更改 2022-01-01