Remove index.php in CodeIgniter_2.1.4

2019-08-14 00:02发布

问题:

I am newbie in Codeigniter and trying to configure Codeigniter.

But i am unable to remove the index.php from url..

I changed the .htaccess file by following data which was given in userguide..

.htacess file contains

RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

and also changed the config file

$config['index_page'] = '';

when i try to use the following url it results

The requested URL /codeigniter/pages/view was not found on this server.

http://localhost/codeigniter/pages/view

But i try with index.php in url..The page shown normally..

http://localhost/codeigniter/index.php/pages/view

Is that .htaccess problem or i have to change some other files..?

How to get rid of this problem?

Any Suggestions, acceptable.

Update

I am using ubuntu 3.10

I used the following command to enable module rewrite

 sudo a2enmod rewrite

The result as follows

  Module rewrite already enabled

I changed the permissions in

  /etc/apache2/sites-enabled/000-default

As

ServerAdmin webmaster@localhost

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

After changing this file also no luck..

回答1:

Finally i found the answer to my question.As the below .htaccess solved my problem..

    <IfModule mod_rewrite.c>

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

    </IfModule>

Thanks to all..



回答2:

in your httpd.conf (on windows)

uncomment below line

LoadModule rewrite_module modules/mod_rewrite.so

in ubuntu enable mod_rewrite using sudo a2enmod rewrite

Restart apache after making changes



回答3:

Make this changes

In config.php

$config['index_page'] = '';

IN root .htaccess file

DirectoryIndex index.php

RewriteEngine On

RewriteCond $1 !^(index\.php|themes|utils|robots\.txt|favicon\.ico)

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

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


回答4:

Nobody mentioned change the setting. In your httpd config file find and change it like this

<Directory "/var/www/html">  # your DocumentRoot setting
    Options FollowSymLinks
    AllowOverride All  # default is None
    Order allow,deny
    Allow from all
</Directory>