2011-03-01 101 views
27

我無法從Codeigniter中的URL中刪除index.php。我和笨1.7做了一些網站和我過去在2從URL刪除index.php - Codeigniter 2

不起作用的.htaccess代碼,我使用

<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteBase/

RewriteCond %{REQUEST_URI} ^system.* 
RewriteRule ^(.*)$ /index.php?/$1 [L] 

RewriteCond %{REQUEST_URI} ^application.* 
RewriteRule ^(.*)$ /index.php?/$1 [L] 

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

<IfModule mod_rewrite.c> 
RewriteEngine on 
RewriteCond $1 !^(index\.php|images|robots\.txt|css) 
RewriteRule ^(.*)$ ./index.php/$1 [L] 

</IfModule> 

我試着也試過它沒有RewriteBase /英寸

我已經改變了$ config ['uri_protocol'] REQUEST_URI和QUERY_STRING和沒有。

我已經設置了$ config ['index_page'] =「」;

文件結構是192.168.0.130/(site)/,所以它必須回到服務器的根目錄,並且找不到index.php文件。

所有我所作出的控制器可以通過將192.168.0.130/(site)/index.php/testcontroller

謝謝到達。

道歉,如果這已被問及之前 - 我看了,並嘗試我可以看到。

編輯:

我還要補充一點,我改變了默認文件夾是

應用

CI-2.0

的index.php

和修改的路徑中index.php是正確的。

+0

你有沒有在父文件夾中的任何htaccess文件? – timwebdev

+0

有一個htaccess文件。它只有一行,它是一個不同的項目 - 我只是試着評論它,但它沒有做任何事情。 – Paul

+0

Btw:系統和應用程序RewriteConds必須以/ SUBFOLDER/ – timwebdev

回答

22

嘗試使用您發佈的第一個代碼塊,而不是/index.php嘗試使用/(site)/index.php(obv用您的站點文件夾命名的obv替換(site))。

+0

我只是試過了,它沒有工作。這將會變成我錯過的一些愚蠢的東西......謝謝你的幫助。 – Paul

+0

我剛把它移到我的本地服務器上,它可以與這些.htaccess設置一起使用,所以它一定是服務器問題。 – Paul

+2

這可能聽起來像一個愚蠢的問題,但你最初測試的服務器是否啓用了mod_rewrite? – Jazzerus

14

這爲我工作:

  1. 創建htaccess文件
  2. 設置$配置[ 'index_page']爲空(config.php文件)
  3. 串設置$配置[ 'uri_protocol'] ='REQUEST_URI'; (config中。PHP)

這是我的htaccess文件:

Options -Indexes 
Options +FollowSymLinks 

RewriteEngine On 
RewriteBase/

#Removes access to the system folder by users. 
#Additionally this will allow you to create a System.php controller, 

RewriteCond %{REQUEST_URI} ^system.* 
RewriteRule ^(.*)$ index.php?/$1 [L] 

#When your application folder isn't in the system 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] 

# 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 

來源:

http://taggedzi.com/articles/display/codeigniter-2-htaccess-and-friendly-urls

+0

謝謝。我確實使用與本地服務器和生產服務器上的配置相同的配置正常工作,因此它一定是我們所擁有的dev服務器的問題。 – Paul

+0

謝謝羅賓,你的建議運行良好。 – ericbae

+0

對不起,我嘗試了每個htaccess代碼,我挖掘了Google 5天,嘗試了每個htaccess代碼示例,但每個都失敗了。但是,最後這段代碼正在爲我添加 'RewriteBase/my/base/site/url'.htaccess代碼。 在添加上面的行之前,當我嘗試調用我的CI控制器時,它正在localhost wamp頁面上重定向。 所以,我上面的代碼爲 'RewriteBase' //config.php $配置[ 'BASE_URL'] \t = '' 加入; $ config ['index_page'] =''; $ config ['uri_protocol'] \t ='REQUEST_URI'; 他他.. :) Coooollll !!!!!羅賓摩根和非常感謝你.. :) –

2

下從其他人,並從該CodeIgnitor URL documnetation所有指令後,不要忘了重啓服務器。我只是忘了這麼做,並不斷嘗試所有其他解決方案。

+0

請注意:某些網絡主機不需要您在更新.htaccess文件後重新啓動服務器。例如,hostgator.com不需要重新啓動: http://support.hostgator.com/articles/specialized-help/technical/apache-htaccess/must-i-restart-apache-after-changing-a-htaccess - 文件 –

3
RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-f 

RewriteCond %{REQUEST_FILENAME} !-d 

RewriteRule ^(.*)$ index.php?/$1 [L] 

這多少在根文件夾時,才需要添加此爲.htaccess

+0

這是唯一已經在我的本地(wamp上的xamp)和託管服務器(燈)上運行的htaccess, – dsdsdsdsd

1

我是在這個2天..嘗試一切可能的。我剛出來的時候,你需要以下條件:

TYPE:

sudo nano /etc/apache2/sites-available/default 

,並更改設置AllowOverride無到有的allowOverride全部 - 這將給你的.htaccess文件訪問

<Directory /var/www/> 
      Options Indexes FollowSymLinks MultiViews 
      AllowOverride All 
      Order allow,deny 
      allow from all 
      # Uncomment this directive is you want to see apache2's 
      # default start page (in /apache2-default) when you go to/
      #RedirectMatch ^/$ /apache2-default/ 
</Directory> 

而且也啓用阿帕奇國防部重寫:

http://stackoverflow.com/questions/3131236/how-do-you-enable-mod-rewrite 

希望這會有所幫助, Mário

1

您只需要在.htacess中添加以下代碼即可。

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

1)在你的根文件夾中創建.htaccess文件

在應用程序文件夾

$config['base_url'] = 'http://localhost/projectName'; 

$config['index_page'] = '';   // remove index.php 

我希望它會工作

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

2)編輯的application/config/config.php文件對你來說