2015-01-12 138 views
0

我試圖從url中刪除index.php過去4天,但沒有成功。在codeigniter中刪除index.php -htaccess

http://domainName.com/CI/index.php/controller-name/function/parameter

CI是GoDaddy的託管文件夾。

/
的.htaccess
CI

谷歌搜索後,我試着用下面的代碼,但只得到一個空白頁或錯誤:500,也是我不明白的邏輯。請有人幫我找到我出錯的地方。

RewriteEngine on 
RewriteCond $1 !^(index\.php|[Javascript/CSS/Image root Folder name(s)]|robots\.txt) 
RewriteRule ^(.*)$ /index.php/$1 [L] 

第二

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

我也改了行,CI /應用/配置/ config.php文件

$config['index_page'] = '';

$config['uri_protocol'] = 「REQUEST_URI」

+0

試試這個: HTTP://計算器.com/questions/14783666/codeigniter-htaccess-and-url-rewrite-issues/14807463#14807463 –

+0

如何在godaddy服務器中允許override(apache.conf)..在我的服務器中什麼都不起作用。我的base_url是http://domain.com/ci/ –

回答

0

這應該工作

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^(.*)$ CI/index.php/$1 [L] 
+0

在你的例子中,你沒有使用RewriteBase將它設置爲CI文件夾,因爲在你的應用程序所在的文件夾中。這是一個動態設置RewriteBase的例子。它可能是有用的。 http://stackoverflow.com/questions/21062290/set-rewritebase-to-the-current-folder-path-dynamically –

+0

即使添加RewriteBase/CI ..它不起作用,任何其他解決方案。 –

0

剛試試這個工作指回復我

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

只是將其保存在您的HTT文件中並嘗試 – Prasanna

+0

感謝您的答案,但它不起作用。沒有指定輸入文件。 –

0

按照以下的步驟:

  1. 更改配置文件是這樣的:

    $配置[ 'index_page'] = '';

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

  2. 使用下面的.htaccess:

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

注:的.htaccess取決於服務器。有些服務器(例如:Godaddy的)需要使用下面的.htaccess:

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

see here

使用在BASE_URL下面的代碼:

$config['base_url'] = 'http' . ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 's' : '').'://'.$_SERVER['HTTP_HOST'].str_replace('//','/',dirname($_SERVER['SCRIPT_NAME']).'/'); 
+0

在apache.conf中更改允許ovveride後,它在localhost中工作正常。即使在godaddy服務器中沒有解決問題,它也會顯示「沒有指定輸入文件。」。將您的htaccess代碼放到URL domainName.com/CI/index時。 php/controller-name/function /參數更改爲domainName.com /?/ controller-name/function/parameter ...任何幫助。 –

+0

您需要爲godaddy使用最後的.htaccess。這是一個特例。 –

+0

我是否需要在上面提到的htaccess代碼中輸入文件夾名稱ci –