2

I have researched on all the question on stackoverflow to remove index.php from codeigniter but still i am unable to do it. Only landing page opens but rest of the pages are blank. I m using own ubuntu linux server. My rewrite module is also on. I tried $config['uri_protocol'] with all possible values. AUTO, PATH_INFO, QUERY_STRING, ORIG_PATH_INFO. My htaccess code is here

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

vhost file is here

DocumentRoot /home/black-sheep/black-sheep.org

    <Directory />
            Options FollowSymLinks
            AllowOverride FileInfo
    </Directory>

    <Directory /home/black-sheep/black-sheep.org/>
            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 /var/log/apache2/error.log

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

    CustomLog /var/log/apache2/access.log combined

My website url is

http://black-sheep.org/

This is the path when i echo __FILE__ on index.php

/home/black-sheep/black-sheep.org/index.php

Its amazing that wordpress site on same server without index.php is running good with following htaccess.

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

I tried with this htaccess also but it doesn't work for me.

Please suggest me the solution. Thanks in advance

2
  • is mod_rewrite enabled ? Commented Dec 19, 2013 at 7:04
  • yes it is.. and i m sure.. Commented Dec 19, 2013 at 7:08

4 Answers 4

4

I have same problem. And I fix it. You must add .htaccess file in root directory of your site

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

And main you must change site conf in /etc/apache2/apache2.conf.
Search Directory /var/www/ Change AllowOverride None -> AllowOverride All

<Directory /var/www/>
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>
Sign up to request clarification or add additional context in comments.

1 Comment

Your solution makes the output Error 500
2
    How to remove index.php in localhost(Ubantu) using codeigniter

   sudo nano /etc/apache2/apache2.conf
    write this code below.

   <Directory /var/www/>
     Options Indexes FollowSymLinks
     AllowOverride All
     Require all granted
  </Directory>

  within codeigniter framework config/config.php
  In application/config/config.php change:

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

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

 make .htaccess file main folder directory

<IfModule mod_rewrite.c>
  RewriteEngine On
 #RewriteBase /
  RewriteCond %{REQUEST_FILENAME} !-f
 RewriteRule ^ index.php [QSA,L]
</IfModule>

Comments

1

Try this solution.

Paste this below code into .htaccess file and move it to you codeigniter folder

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

3 Comments

what is the value you have added on $config['index_page'] on config.php
It is CI default AUTO
can you make it as $config['index_page'] == '' ; Let me know if still problem exists
1

I was facing the same problem but able to correct it. I am giving you the full instruction. follow step by step..

First check whether mod_rewrite is on or not from Terminal by typing the below command :

sudo a2enmod rewrite

Then open file apache2.conf which is located in the below mentioned directory

/etc/apache2/apache2.conf

Find <Directory /var/www/> in the file and change AllowOverride None to AllowOverride All

If it is not allowing you to save the file, that means the directory don't have the required permission. so please give that by running the below command.

sudo chmod -R 777 /etc/apache2/ and then save the file.

Now write your .htaccess file and save the file by placing the below codes.

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

Then restart your apache service once by the below command

sudo service apache2 restart

Hopefully, then it will work...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.