11

How to remove index.php in codeigniter on Windows Azure and IIS?

Can I rewrite the URL for the index.php of Codeigniter without a particular module?

Mischa
  • 42,876
  • 8
  • 99
  • 111
Romain Beuque
  • 159
  • 1
  • 2
  • 9

3 Answers3

15

You can add rewrite rules in your web.config file. Add the following to the system.webServer section:

<rewrite>
  <rules>
    <rule name="Rule" stopProcessing="true">
      <match url="^(.*)$" ignoreCase="false" />
      <conditions>
        <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
        <add input="{URL}" pattern="^/favicon.ico$" ignoreCase="false" negate="true" />
      </conditions>
      <action type="Rewrite" url="index.php/{R:1}" appendQueryString="true" />
    </rule>
  </rules>
</rewrite> 
Mischa
  • 42,876
  • 8
  • 99
  • 111
  • This setting should work on most php frameworks (zend 1/2, laravel etc) – Bryan P Sep 17 '14 at 01:03
  • This wasn't working for me and then I realized that I moved the reference to my index.php file to within an application folder (for Codeigniter) so perhaps a good thing to remember is that this file should be where the index.php file is for you. – Dusan Apr 27 '16 at 02:27
10

Create a file name web.config in wwwroot

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="Imported Rule 1" stopProcessing="true">
                    <match url="^(.*)$" ignoreCase="false" />
                        <conditions logicalGrouping="MatchAll">
                            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                        </conditions>
                        <action type="Rewrite" url="index.php?url={R:1}" appendQueryString="true" />
                </rule>
            </rules>
        </rewrite> 
    </system.webServer>
</configuration>
n9ti
  • 156
  • 1
  • 4
1

You can also implement other rewrite rules like

<rule name="a rule">
<match url="^xxx/(.*)/(.*)-(.*)\.xxx" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
<action type="Rewrite" url="controller/method/{R:3}" />
</rule>

with one condition, is to change $config['url_protocal']='PATH_INFO'; in config/config.php this will tell URL rewrite module to use re-writed URI instead of original URL, otherwise you will have 404 page not found problem.