Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

This question already has an answer here:

I know this question is being ask already, i tried all those but still unable to remove index.php from url. Here are my details

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

.htacess look like:

RewriteEngine On
RewriteBase /projectname

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

I also look at the below link but no luck.. Cannot remove index.php from url CI based site

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

My "/etc/apache2/sites-available/default" is look like this:

<VirtualHost *:80>
    ServerAdmin webmaster@localhost

    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>

Any help appreciated!!

share|improve this question
Anything suspicious in your logs? – Mike Anthony May 15 at 4:53
And what is your $config['uri_protocol'] set to? – Mike Anthony May 15 at 5:00
And, lastly, what error do you get. I suspect "Object Not Found"? – Mike Anthony May 15 at 5:15
@MikeAnthony i am getting "The requested URL /projectname/aboutus was not found on this server." – Suresh Kamrushi May 15 at 5:25
And the other questions? Also, what happens when you visit the projectname root? And, what happens when you visit the root of the host (localhost)? – Mike Anthony May 15 at 5:27
show 8 more comments

marked as duplicate by cryptic ツ, hjpotter92, flav, tkanzakic, Roman C May 15 at 6:59

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

3 Answers

my .htaccess

RewriteEngine on

RewriteCond $1 !^(index.php)

RewriteRule ^(.*)$ index.php/$1 [L]
share|improve this answer
I tried this no success – Suresh Kamrushi May 15 at 4:49
change httpd.conf, AllowOverride None -> AllowOverride All – blu May 15 at 4:58
It looks like it already is: See <Directory /var/www/> in the asker's code. – Mike Anthony May 15 at 5:13
@blu: i change "AllowOverride None" to "AllowOverride All" and restarted my apache but no success. – Suresh Kamrushi May 15 at 5:31
create a new directory, test your web server supports rewrite. – blu May 15 at 6:55

In application/config/config.php change:

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

to:

$config['index_page'] = '';

it is a good idea to do apache reload everytime you change an apache config file.

sudo /etc/init.d/apache2 reload

or:

sudo service apache2 reload

or:

sudo /etc/init.d/httpd reload

(or whatever is the equivalent command for your platform)

for what it is worth, here is my .htaccess

RewriteEngine on
RewriteBase /
RewriteCond $1 !^(index\.php|static|robots\.txt|favicon\.ico|uploads|googlexxxxxxxx\.html|mobile.html)
RewriteRule ^(.*)$ index.php/$1 [L]
share|improve this answer
yes i updated that one also. – Suresh Kamrushi May 15 at 4:42
yes restarted my apache number of time. no use. – Suresh Kamrushi May 15 at 4:46
tried with your htaccess file no success. i change "RewriteBase /projectname" as my ci is under this folder. – Suresh Kamrushi May 15 at 4:51

Enabled mod rewrite

set your htaccess (sample)

<IfModule mod_rewrite.c>
  RewriteEngine On
  #RewriteBase /

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

remove index.php in your config

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

Also allow overriding htaccess in your apache

/etc/apache2/sites-available/default

and edit the file & change to

AllowOverride All

and

Restart Apache

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.