2017-03-05 38 views
0

我正在嘗試使用PHP & MySQL在本地構建購物車。我的主要目錄是/ Library/WebServer/Documents。我試圖設置它,以便我可以在沒有index.php的情況下訪問localhost/project。codeigniter - 我的htaccess有什麼問題?

這裏是我的htaccess:

Options +FollowSymLinks 
Options -Indexes 
DirectoryIndex index.php 
<IfModule mod_rewrite.c> 
    RewriteEngine on 
    RewriteCond $1 !^(index\.php|resources|images|css|js|robots\.txt|favicon\.ico) 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteRule ^(.*)$ index.php/$1 [L,QSA] 
</IfModule> 
<IfModule !mod_rewrite.c> 
    ErrorDocument 404 /index.php 
</IfModule> 

我的配置代碼(提取,而不是整個事情):

$config['base_url'] = 'http://localhost/project/'; 
$config['index_page'] = ''; 
$config['uri_protocol'] = 'REQUEST_URI'; 

顯然有這個錯誤。即使我設法訪問本地主機/項目沒有index.php,我無法查看由我的控制器代碼生成的頁面(例如,如果我嘗試去本地/項目/歡迎我得到這個錯誤消息:'請求的URL /項目/歡迎在此服務器上找到。」本地主機/項目/歡迎應該帶我去的welcome.php網頁在我的控制器文件夾。

Here's a snapshot of the file structure

有人能向我解釋什麼是錯我的代碼?

+0

通常情況下,你不會有''在目錄views'文件.htaccess'。至少在安裝新的CI時沒有這樣的文件。 – Tpojka

+0

@vnguyen你需要從URL刪除index.php? –

回答

0

你的意思是沒有.php嗎?

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^([^\.]+)$ $1.php [NC,L] 

刪除此DirectoryIndex index.php! 它設置URL

+0

謝謝,修好了! – vnguyen

0

使用此背後的.htaccess在index.php:

<IfModule mod_rewrite.c> 
    RewriteEngine On 
    RewriteBase/

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