简体   繁体   中英

CodeIgniter Removing index.php using .htaccess file

Removing index.php in CodeIgniter using .htaccess file is not working for me. I Tried following code eventhough not working.

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

I tried this http://firstcode.info/codeigniter-removing-index-php-from-url/ . But not working.But its working in my localhost. I also edited httpd.config file.But off no use. Please help me.

STEP 1

Open the folder “application/config” and open the file “config.php“. find and replace the below code in config.php file.

find the below code

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

replace with the below code

$config['index_page'] = "

STEP 2

Write below code in .htaccess file

    <IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L,QSA]
   </IfModule>

STEP 3

“application/config/config.php“, then find and replace the below code

find the below code

$config['uri_protocol'] = "AUTO"

replace with the below code

$config['uri_protocol'] = "REQUEST_URI" 

Your mentioned code is correct.

You have to modify apache2.conf (/etc/apache2/apache2.conf --- its my servers path) check your path.

Find this culprit "AllowOverride None" and /var/www/ or /var/www/html

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

update to

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

Dont forget to sudo service apache2 restart

Try this code

<IfModule mod_rewrite.c>
    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]

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

<IfModule !mod_rewrite.c>
    ErrorDocument 404 /index.php 
</IfModule>

In my config.php file ihave following settings.

$config['index_page']   = "";
$config['uri_protocol'] = "PATH_INFO";

Please try change base url as well in config.php, If using localhost or domainname.com

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

OR

$config['base_url'] = 'http://domainname.com/'; // domainname.com

add in .htacess

RewriteEngine on
RewriteCond $1 !^(index\.php|public|\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$

remove "index.php" from $config['index_page'] in config.php (keep blank value)

and fix the permission of project folder.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM