2012-12-04 103 views
0

我一直工作在這一個小時了,所以我想我還不如問刪除的index.php。與笨的.htaccess

我想從我的CodeIgniter應用程序的URL中刪除index.php文件並不能做到這一點。

應用程序是在我的辦公室在專用服務器上運行,我通過URL http://smr_local

訪問應用程序這是我的基本虛擬主機塊

<VirtualHost 192.168.1.90:80> 
    ServerAdmin [email protected] 
    DocumentRoot "/var/www/smr.dev/app" 
    ServerName smr_local 
    ErrorLog "/etc/httpd/logs/error_log" 
    CustomLog "/etc/httpd/logs/access_log" common 
    <Directory /var/www/smr.dev/app> 
     Order allow,deny 
     Allow from all 
     AllowOverride All 
    </Directory> 
    <IfModule mod_rewrite.c> 
     RewriteEngine on 
    </IfModule> 
</VirtualHost> 

這裏是我的.htaccess文件

RewriteEngine on 
RewriteBase/
# Hide the application and system directories by redirecting the request to index.php 
RewriteRule ^(application|system|\.svn) index.php/$1 [L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ /index.php/$1 [QSA,L] 

而且我的配置文件

$config['base_url'] = "http://smr_local/"; 
$config['index_page'] = ''; 
$config['uri_protocol'] = 'REQUEST_URI'; 

現在,當我試圖訪問我的基本URL http://smr_local/user/courses我得到了我的Apache的錯誤日誌中的錯誤我得到這個。

File does not exist: /var/www/smr.dev/app/user 

我真的不知道接下來要做什麼。任何幫助,將不勝感激。

回答

1

你檢查官方user guide

example.com/index.php/news/article/my_article 

您可以輕鬆地通過使用.htaccess文件有一些簡單的規則刪除此文件。下面是這樣一個文件的一個例子,使用「負」的方法中,一切都被重定向除指定的項目:

RewriteEngine on 
RewriteCond $1 !^(index\.php|images|robots\.txt) 
RewriteRule ^(.*)$ /index.php/$1 [L] 

在上述例子中,比那些的index.php,圖像之外的任何HTTP請求時,而robots.txt被視爲您的index.php文件的請求。


我一直在與笨以前,這就是我如何得到它的工作:

這裏是我的.htaccess(假設你的默認文件夾結構):

<IfModule mod_rewrite.c> 
    RewriteEngine On 
    RewriteBase/

    # Removes access to the system folder by users. 
    RewriteCond %{REQUEST_URI} ^system.* 
    RewriteRule ^(.*)$ /index.php?/$1 [L] 

    # Prevents user access to the application folder 
    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> 
    ErrorDocument 404 /index.php 
</IfModule> 

也就是說的config.php相關部分:

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

如果這不起作用,您的問題可能在Apache配置中。

然後提供httpd.conf和其他相關的配置,不僅virtual-hosts

+0

是的,那是我第一次嘗試。不起作用。 – nicks451

+0

@ nicks451我已經更新了答案,請看看。 –