Remove index.php from the address bar from CodeIgniter

 

It is possible to remove index.php from the web browser address bar when CodeIgniter is running. This can be done by following these steps:

  1. Create or open a .htaccess file. If a .htaccess file does not already exist, you can create one using the following:
    • Linux/Mac: Open a terminal window and type the following:
      touch /path/to/CodeIgniter/.htaccess
      
    • Windows: Create a text file in your CodeIgniter root, naming it file.htaccess. Hold down the Windows key and then press R to open the Run dialogue. Enter the following command and click on OK:
      ren "C:pathtoCodeIgniterfile.htaccess" .htaccess
      
  2. Once your .htaccess file is opened, write the following lines at the top of the file:
    <IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond $1 !^(index.php|images|robots.txt)
    RewriteRule ^(.*)$ index.php/$1 [L]
    </IfModule>

About the author

Deven Rathore

I'm Deven Rathore, a multidisciplinary & self-taught designer with 3 years of experience. I'm passionate about technology, music, coffee, traveling and everything visually stimulating. Constantly learning and experiencing new things.

  • Prashant

    Some server side configuration you need to check
    01 Apache rewrite enabled

    02 in your httpd.conf directive is important

    ServerAdmin [email protected]
    ServerName dev.local
    ServerAlias http://www.dev.local
    DocumentRoot /var/www/html/dev.local/public_html
    ErrorLog ${APACHE_LOG_DIR}/dev.local.error.log
    CustomLog ${APACHE_LOG_DIR}/dev.local.access.log combined

    AllowOverride All

    • Deven Rathore

      thanks for sharing

Pin It on Pinterest

Shares