2013-05-15 68 views
12

我知道這個問題已被問到,我試過所有這些,但仍然無法從url中刪除index.php。 這裏是我的細節如何從UBUNTU的codeigniter中刪除index.php

Ubuntu 12.10 
PHP : 5.4.6 
Mod_rewrite in on 
CI verson: 2.1 

.htacess樣子:

RewriteEngine On 
RewriteBase /projectname 

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

我也看看下面的鏈接,但沒有運氣.. Cannot remove index.php from url CI based site

How to remove "index.php" in codeigniter's path

我「/ etc/apache2/sites-available/default「看起來像這樣:

<VirtualHost *:80> 
    ServerAdmin [email protected] 

    DocumentRoot /var/www 
    <Directory /> 
     Options FollowSymLinks 
     AllowOverride None 
     </Directory> 
    <Directory /var/www/> 
     Options Indexes FollowSymLinks MultiViews 
     AllowOverride All 
     Order allow,deny 
     allow from all 
    </Directory> 

    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ 
    <Directory "/usr/lib/cgi-bin"> 
     AllowOverride None 
     Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch 
     Order allow,deny 
     Allow from all 
    </Directory> 

    ErrorLog ${APACHE_LOG_DIR}/error.log 

    # Possible values include: debug, info, notice, warn, error, crit, 
    # alert, emerg. 
    LogLevel warn 

    CustomLog ${APACHE_LOG_DIR}/access.log combined 
</VirtualHost> 

任何幫助讚賞!

+0

任何可疑你的 日誌? –

+0

你的'$ config ['uri_protocol']'設置爲什麼? –

+0

最後,你會得到什麼錯誤。我懷疑「未找到物體」? –

回答

5

application/config/config.php變化:

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

到:

$config['index_page'] = ''; 

這是一個好主意,做的apache重裝每次你改變了Apache的配置文件。

sudo /etc/init.d/apache2 reload 

或:

sudo service apache2 reload 

或:

sudo /etc/init.d/httpd reload 

(或者是用平臺的等效命令)

什麼值得注意的是,這裏是我的。 htaccess

RewriteEngine on 
RewriteBase/
RewriteCond $1 !^(index\.php|static|robots\.txt|favicon\.ico|uploads|googlexxxxxxxx\.html|mobile.html) 
RewriteRule ^(.*)$ index.php/$1 [L] 
+0

是的,我更新了一個也。 –

+0

是的重新啓動我的Apache時間。沒用。 –

+0

嘗試使用您的htaccess文件沒有成功。我更改「RewriteBase/projectname」,因爲我的ci位於此文件夾下。 –

0

我的.htaccess

RewriteEngine on 

RewriteCond $1 !^(index.php) 

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

我試過這個沒成功 –

+0

更改httpd.conf,AllowOverride無 - > AllowOverride全部 – blu

+0

看起來已經是這樣了:請參見提問者代碼中的'。 –

46

第1步:

刪除索引:

在htaccess文件

<IfModule mod_rewrite.c> 
    RewriteEngine On 
    #RewriteBase/

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

第2步添加這一點。PHP在笨配置

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

第3步:

允許在Apache的配置(命令)壓倒一切的htaccess

sudo nano /etc/apache2/apache2.conf 

和編輯文件&變化

AllowOverride All 

爲www文件夾

步驟4:

啓用阿帕奇國防部重寫(命令)

sudo a2enmod rewrite 

步驟5:

重啓Apache(命令)

sudo /etc/init.d/apache2 restart 
+1

最好的解決方案,像一個魅力工作..非常感謝 – user2899728

+0

最後!一個工作解決方案Setp'5'也可以很簡單:'service apache2 restart' – FireBrand

+1

是的,這個解決方案適用於codeigniter 3.x + ubuntu 16.04 –