Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove index.php of Codeigniter on IIS?

I understand I can remove the 'index.php' part of the url with the following web.config code:

<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>

Problem is I have CI installed in a sub-directory (mydomain.com/codeigniter) and I'm having trouble understanding the web.config file.

Do you know how to change this so it works for a sub-directory?

like image 937
stuartb Avatar asked Oct 09 '12 20:10

stuartb


1 Answers

I have WordPress in the root directory and my CodeIgniter application in a sub-directory. I create a similar web.config like yours and save it in the sub-directory. My CI app doesn't need the index.php in url any more.

At first, I add my sub-directory in the <action url="myapp/index.php/{R:1}"...> and wish it could be restricted to look into the sub-directory only but fails. I remove the sub-directory and leave it to original but move the web.config to the subdirectory and it works.

Therefore, I think maybe you may create two web.config files with different rules and saves them in different directory.

Another note might help: enable the error message to output the detail from IIS. I use the tricks to find out how IIS looks for my files. It is <httpErrors errorMode="Detailed" />, <asp scriptErrorSentToBrowser="true"/>, and the <system.web> section as below:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>

    <system.webServer>

        <httpErrors errorMode="Detailed" />
        <asp scriptErrorSentToBrowser="true"/>

        <rewrite>
        <rules>
            <rule name="RuleRemoveIndex" 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" />
                </conditions>
                <action type="Rewrite" url="index.php/{R:1}" appendQueryString="true"/>
            </rule>
        </rules>
        </rewrite>

    </system.webServer>

    <system.web>
        <customErrors mode="Off"/>
        <compilation debug="true"/>
    </system.web>

</configuration>
like image 161
Amigo Chan Avatar answered Sep 18 '22 08:09

Amigo Chan