![](/img/trans.png)
[英]codeigniter .htaccess in amazon ec2 removal of index.php not working
[英]Site not working after removal of Index.php from urlstring?
在我的舊 url 中,它是http://localhost/midas/index.php
我的網站正在使用帶有 CodeIgniter 的 MVC 框架。
我在 Apache XAMPP 中激活了 mod_rewrite 並使用了以下 htaccess 代碼:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /index.php/$1 [NC,R=301,L]
當我輸入我的基礎 url 時,它很好,我的主頁加載:
基礎 url = http://localhost/midas/
但是,當我單擊導航菜單或鏈接時,我會收到 404 object not found 錯誤消息。
Apache 錯誤信息:
[2011 年 7 月 12 日星期二 13:48:55] [錯誤] [客戶端 127.0.0.1] 文件不存在:C:/xampp/htdocs/midas/site,引用者: http://localhost/
有什么我需要改變的地方嗎?
編輯/application/config/config.php
並更改
$config['index_page'] = 'index.php';
至
$config['index_page'] = '';
此外,您需要在啟用mod_rewrite
后重新啟動 Apache 。
這是我與.htaccess
一起使用的 .htaccess(已修改,因此它應該適合您):
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /midas/
#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
RewriteCond $1 !^(index\.php|images|css|robots\.txt)
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>
它應該在您的根目錄中(即C:\xampp\htdocs\midas
)。
您可能需要在 htaccess 中設置 RewriteBase
見: http://httpd.apache.org/docs/current/mod/mod_rewrite.html
我的猜測是
RewriteBase /midas
(在RewriteEngine
之后)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.