2013-04-17 42 views
1

我一直拉着我的頭髮三天,我搜索了一切,一直在代碼點火器論壇上,並從頂部到底部檢查堆棧溢出。無法從CodeIgniter中的URL中刪除index.php

我想要做的就是從url中刪除index.php。我發現我的問題最近的帖子沒有回答: Post

如果我去localhost/CodeIgniter我的主頁面顯示。如果我點擊我的鏈接,則會出現頁面不存在的錯誤。

404 Page Not Found 

The page you requested was not found. 

基於我已閱讀的一切,這裏是我目前的配置。

MAC OSX 10.8.3 MAMP 笨2.1.3

我的根目錄是WWW /笨/ 這裏是.htaccess文件是在笨根

#Deny from all 
<IfModule mod_rewrite.c> 
    RewriteEngine On 
    RewriteBase /CodeIgniter/ 

    #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的配置設置:我嘗試了沒有成功的uri_protocol的所有設置

$config['index_page'] = ''; 
$config['uri_protocol'] = 'AUTO'; 

我ve已經啓用了mod_rewrite,並且AllowOverride在httpd.conf中設置爲All。

****更新 所以我刪除了MAMP和codeigniter,並從頭開始。現在使用下面的.htaccess文件,當我到localhost codeigniter文件夾不顯示。如果我嘗試瀏覽到該文件夾​​,則會收到以下錯誤消息。

Internal Server Error 

The server encountered an internal error or misconfiguration and was unable to complete your request. 

Please contact the server administrator, [email protected] and inform them of the time the error occurred, and anything you might have done that may have caused the error. 

More information about this error may be available in the server error log. 

當我查看錯誤日誌,我有以下錯誤。

[Mon Apr 22 21:42:51 2013] [alert] [client ::1] /Users/me/Dropbox/www/codeigniter/.htaccess: <IfModule takes one argument, Container for directives based on existance of specified modules 

我證實我在我的phpinfo()中啓用了mod_rewrite;

如果我刪除.htaccess文件,我可以瀏覽到該文件夾​​並獲取主頁面,但當然鏈接不起作用。任何建議將不勝感激。

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

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

兩個小時沒事嗎?我非常驚訝 – Drewdin

+0

僅用於測試目的,請備份當前的htaccess文件並將其替換爲此文件,然後查看是否可以無誤瀏覽。 –

回答

0

猶未晚,但我不得不改變我的httpd.conf文件,如經過三次重新啓動它剛開始工作。也許這可以幫助別人

<Directory /> 
    Options FollowSymLinks 
    AllowOverride All 
    Order deny,allow 
    Deny from all 
</Directory> 
0

只是爲了測試目的備份htaccess文件,然後清除它完全貼在於此:

RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule .* index.php/$0 [PT,L] 

看看你是否可以瀏覽該網站沒有錯誤。

+0

我更新了我的.htaccess,當我點擊我的任何鏈接時,仍然出現錯誤。以下是我的鏈接,以防萬一。 About Drewdin

0

嘿,你爲什麼不做一件事...下載此代碼點火器安裝https://github.com/amitavroy/cleanplate然後檢查這是否沒有錯誤。您mod_rewrite的應該是offcourse

+0

我現在下載它。 mod_rewrite已啓用。 – Drewdin

+0

好的。請讓我知道該代碼是否適合您。 –

+0

您的模板會打開主頁,但沒有鏈接工作。 – Drewdin

0
DirectoryIndex index.php 
RewriteEngine on 
RewriteBase/
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond $1 !^(index\.php|robots\.txt) 
RewriteRule ^(.*)$ index.php?/$1 [L] 


內部配置文件:亡羊補牢

$config['index_page'] = 'index.php'; 
$config['uri_protocol'] = 'REQUEST_URI'; //or 'QUERY_STRING' 
+0

我試過你的建議,如果我點擊鏈接,但仍然可以得到404錯誤,但網頁出現正常。鏈接現在添加index.php這是我想要的相反。 – Drewdin

+0

@Drewdin:正如我在下面的註釋中提到的,site_url()會將「index.php」附加到base_url()。 'site_url('about')= your_base_url/index.php/about'。但是如果U使用'base_url('about')= your_base_url/about'。 –

+0

但是如果你已經在很多地方使用了'site_url()',那麼在config.php中刪除index.php'$ config ['index_page'] ='';'。 –

0

只需粘貼.htaccess文件下面,將工作

RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ /CodeIgniter/index.php/$1 [L] 

設置 $配置[ 'index_page'] = ''; //config.php $ config ['uri_protocol'] ='REQUEST_URI'; // config.php