問題描述
我編寫了一個 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 錯誤的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!