Codeigniter web.config or .htaccess index.php rewrite inside a subdirectory Codeigniter web.config or .htaccess index.php rewrite inside a subdirectory codeigniter codeigniter

Codeigniter web.config or .htaccess index.php rewrite inside a subdirectory


I had the same problem but it's working now. Here's what worked for me. Fu Xu's answer was good, but it didn't quite work. So, if you make the following modifications to his code, it may work for you as it did for me.
I changed
<rule name="Rewrite Administration Index">
to
<rule name="Rewrite Administration Index" stopProcessing="true">

then I changed
<match url="administration/(.*)" />
to
<match url="^administrator/(.*)$" ignoreCase="true"/>

then
<conditions>
to
<conditions logicalGrouping="MatchAll">

and also modified this
<add input="{REQUEST_FILENAME}" pattern="css|js|jpg|jpeg|png|gif|ico|htm|html" negate="true" />
to
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />

here's the full code:

<rule name="Rewrite Administration Index" stopProcessing="true">  <match url="^administration/(.*)$" ignoreCase="true"/>  <conditions logicalGrouping="MatchAll">     <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />     <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />  </conditions>  <action type="Rewrite" url="administration/index.php/{R:1}" /></rule><rule name="Rewrite CI Index" stopProcessing="true">  <match url="^(.*)$" ignoreCase="true" />  <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/{R:1}" appendQueryString="true" /></rule>

I hope this works for you


I've just run a mockup as per your folder structure on a Linux System.

I added the standard htaccess file as you find in the codeigniter users guide. So there are two .htaccess files. One in the main application (root) Folder and the other under the administration folder.

Removed the index.php from $config['index_file'] ='' in both config files.

Created a Home controller in both with a whoami method that just echos back "I am the administration home controller page" for the administration Home controller called by /administration/home/whoami and "I am the main home controller" for the /home/whoami.

Both returned their appropriate messages indicating that each is being called correctly.

The .htaccess straight out of the users guide.

RewriteEngine OnRewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME} !-dRewriteRule ^(.*)$ index.php/$1 [L]

So I imagine the same should work with IIS but dont hold me to that.I found something that may help there... web.config version of the .htaccess

So for the above setup you should be able to put in the appropriate urls to hit both CI Instances.


will you try add administration rule before CI Index section as follow:

    <rule name="Rewrite Administration Index">        <match url="administration/(.*)" />        <conditions>            <add input="{REQUEST_FILENAME}" pattern="css|js|jpg|jpeg|png|gif|ico|htm|html" negate="true" />        </conditions>        <action type="Rewrite" url="administration/index.php/{R:1}" />    </rule>    <rule name="Rewrite CI Index">        <match url=".*" />        <conditions>            <add input="{REQUEST_FILENAME}" pattern="css|js|jpg|jpeg|png|gif|ico|htm|html" negate="true" />        </conditions>        <action type="Rewrite" url="index.php/{R:0}" />    </rule>