2015-07-28 37 views
0

基本上我想刪除我的url中的index.php。使用.htaccess刪除index.php無法在codeigniter hostgator上工作

我認爲我的.htaccess在Hostgator上不工作,我已經在這些.htaccess,codeigniter和hostgator上搜索了我的問題。

這是HostGator的我的文件夾結構

/cgi-bin目錄
/httpdocs資料
        | --- /應用
        | --- /系統
        | ---。。htaccess
        | --- index.php文件

.htaccess

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

config.php

$config['base_url'] = 'www.example.com'; // this is only an example because our website is confidential 
$config['index_page'] = ''; 
$config['uri_protocol'] = 'AUTO'; 

編輯:對不起,我是白癡。我發佈了這個問題並且嘗試了下面的答案後聯繫了Hostgator。他們說我 運行在Windows server不是Apache server所以我的.htaccess將 不起作用,所以我需要將它轉換爲web.config。對不起,這些 浪費時間來回答這個問題。謝謝

編輯:我標誌着@Deep巴力的回答是正確的作爲@大衛說,一切正常

+0

你改變了config.php嗎? –

+0

看到我的代碼... !!! –

+0

@DeepParekh是先生我已經改變了config.php –

回答

1

一般我用HostGator的這個htaccess的:

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

確保你改變了你的config.php文件:

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

仍然'404 - 文件或目錄未找到.' –

+0

檢查您的routes.php文件,您定義您的默認控制器,並嘗試通過回聲調試東西.... –

+0

感謝您的幫助先生。我是白癡,在聯繫Hostgator之前先發布了這個問題。 –

0

我認爲它可能使用htaccess的。 http://support.hostgator.com/articles/specialized-help/technical/apache-htaccess/how-to-edit-your-htaccess-file

也許試試這些htaccess。它適用於我的本地項目。

DirectoryIndex index.php 
    RewriteEngine on 

    RewriteCond %{REQUEST_URI} !^(index\.php|\.swf|forums|images|css|downloads|js|robots\.txt|favicon\.ico)$ 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteRule ^(.*) ./index.php [L] 
+0

仍然'404 - 文件或目錄未找到.' –

+0

你有一個網絡服務器或網站空間? – Tobias

+0

你的意思是Hostgator? –

0

。htaccess的看起來:

<IfModule mod_rewrite.c> 
    RewriteEngine On 
    #RewriteBase/

    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteRule^index.php [QSA,L] 



# Removes trailing slashes (prevents SEO duplicate content issues) 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteRule ^(.+)/$ $1 [L,R=301] 
</IfModule> 

在codeiginator配置:

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

如果htaccess並不那麼工作

  1. 配置Apache的mod_rewrite

    a2enmod重寫

  2. 添加以下代碼到/ etc/apache2的/網站可用/默認

    的AllowOverride所有

+0

謝謝你幫助先生。我是白癡,在聯繫Hostgator之前先發布了這個問題。 –

0

config/config.php

$config['base_url'] = ''; 
$config['index_page'] = ''; 

在.htacess

<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ index.php/$1 [L] 
</IfModule 
+0

仍然'404 - 文件或目錄未找到。「 –

+0

您是否刪除了基本網址? –

+0

是的,我刪除它,並測試你發佈的.htaccess代碼,但仍然沒有找到文件 –

0

這是適用於我:

<IfModule mod_rewrite.c> 
    RewriteEngine on 
    RewriteBase/
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteRule ^(.*)$ index.php?/$1 [L] 
</IfModule> 
相關問題