How to remove index.php from url (Code Igniter) using IIS 8.0 server

I downloaded Code Igniter 3.1.7 and am hosting my website on IIS 8. However; I am currently at a stop due to an irritating problem which I have been trying to solve.

My goal is to remove 'index.php' from url when trying to access a controller.

Example: http://localhost/welcome instead of http://localhost/index.php/welcome

Since IIS does not use the htaccess file to create a rule to remove 'index.php' from url. An alternative I tried to do is to use the URL Write add-on provided by IIS.

enter image description here

After I hit Apply. The web.config file is created:

<?xml version="1.0" encoding="UTF-8"?>
                <rule name="Imported Rule 1" stopProcessing="true">
                    <match url="^(.*)$" ignoreCase="false" />
                    <conditions logicalGrouping="MatchAll">
                        <add input="{R:1}" pattern="^(index\.php|assets|images|js|css|uploads|favicon.png)" ignoreCase="false" negate="true" />
                        <add input="%(REQUEST_FILENAME)" matchType="IsFile" ignoreCase="false" negate="true" />
                        <add input="%(REQUEST_FILENAME)" matchType="IsDirectory" ignoreCase="false" negate="true" />
                    <action type="Rewrite" url="./index.php/{R:1}" />

Then I went to application/config/config.php file and changed these variables:

$config['base_url'] = ''; to $config['base_url'] = 'http://localhost/'; $config['index_page'] = 'index.php'; to $config['index_page'] = 'index.php';

Afterwards, I try to access using http://localhost/welcome , But I get this message:

404 - File or directory not found. The resource you are looking for might have been removed, had its name changed, or is temporarily unavailable.

2 answers

  • answered 2018-03-14 00:17 mohamedvall

    Try this

    in you .htaccess file

    RewriteEngine On
    RewriteBase /your_subfolder
    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]
    RewriteCond %{REQUEST_URI} ^application.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L]

    in application/config/config.php

    $config['index_page'] = '';

    update sorry i didn't see that you use IIS 8.0 server

    see :

  • answered 2018-03-14 04:56 Danish Ali

    First set your URL Helper here $autoload['helper'] = array(); in application/config/autoload.php

    Then set your Base URL here like $config['base_url'] = '' Like this

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


    $root=(isset($_SERVER['HTTPS']) ? "https://" : "http://").$_SERVER['HTTP_HOST'];
    $root.= str_replace(basename($_SERVER['SCRIPT_NAME']), '',  
    $config['base_url'] = $root; //$root is your codeigniter project name i.e. eCommerce, example_project

    Now run your application http://localhost/project-folder-name