2012-11-02 25 views
1

通常我訪問一個頁面是這樣的:http://localhost/codeigniter/index.php/auth/login 但是我希望能夠訪問該頁面是這樣的:http://localhost/codeigniter/auth/login如何從我的鏈接中刪除「index.php」?

我沒有任何有關http.conf.htaccess配置。

我在codeigniter/application/config/config.php

我的http.conf文件中設置$config['index_page'] = '';是除uncommentnig其默認「LoadModule rewrite_module modules/mod_rewrite.so

我考察提出了許多.htaccess文件,但我不明白的重寫規則背後的邏輯。

這裏是我最成功的.htaccess內容。它位於/www/CodeIgniter/
(由最成功的我的意思是,這是唯一一個不通過服務器對由笨創建404錯誤)

RewriteOptions Inherit 
Options -Indexes 
Options +FollowSymLinks 
RewriteBase /CodeIgniter/ 
# Set the default file for indexes 
DirectoryIndex index.php 

<IfModule mod_rewrite.c> 

    # activate URL rewriting 
    RewriteEngine on 

    # do not rewrite links to the documentation, assets and public files 
    RewriteCond $1 !^(images|assets|uploads|captcha) 

    # do not rewrite for php files in the document root, robots.txt or the maintenance page 
    RewriteCond $1 !^([^\..]+\.php|robots\.txt) 

    # but rewrite everything else 
    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. 

    ErrorDocument 404 index.php 

</IfModule> 

我討厭請求直接的解決方案然而不幸的是,這是我的最後一招:/ 你能給我一個正確的解決方案來解決我的問題嗎?

+1

嘗試更換'RewriteBase /笨/ '這個'RewriteBase /' – manix

+0

'.htaccess'文件看起來或多或少是正確的。如果鏈接不通過,可能是CodeIgniter問題。在'RewriteBase'之後的位,就像manix所說的那樣,是你的域到你的.htaccess的主目錄之後的路徑,你聲明的是'/ CodeIgniter /',所以應該是正確的。 – Orbling

+0

是否在您的服務器上啓用了rewritemodule?檢查您的.htaccess文件是否正常工作。[link](http://jappler.com/blog/archive/2008/10/22/how-to-test-htaccess-files) –

回答

1

這是我重複回答: Codeigniter issues with paths in localhost (XAMPP)

請創建項目.htaccess文件文件夾和寫入:

<IfModule mod_rewrite.c> 
RewriteEngine On 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 

# Rewrite all other URLs to index.php/URL 
RewriteRule ^(.*)$ index.php?url=$1 [PT,L] 

</IfModule> 
<IfModule !mod_rewrite.c> 
ErrorDocument 404 index.php 
</IfModule> 

你不需要在BASE_URL來定義配置文件:

$config['base_url'] = ''; // blank it. 
0

把這個在您的htaccess

<IfModule mod_rewrite.c> 
RewriteEngine on 
RewriteCond $1 !^(index\.php|resources|robots\.txt) 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ index.php/$1 [L,QSA] 
</IfModule> 

確保重寫模塊服務器上啓用

0

這是最簡單的一個,我發現這對我的作品: -

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