7

my website folder structure is like below...

Application Root
|- administration
|--|- application
|--|- system
|--|- index.php
|--|- web.config
|
|- application
|- system
|- index.php
|- web.config

Two CI framework installed here.

  1. site root
  2. administration folder

Here I am talking about the administration subfolder.

My web.config URL Rewrite is like below.

<rules>
         <rule name="Rewrite to index.php">
            <match url="index.php|robots.txt|images|test.php" />
            <action type="None" />
        </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>
    </rules>

problem is, if I remove index.php from $config['index_page'] of site_root/administration/application/config/config.php, any controller function shows 404 page not found. The site root web.config actually doing this.

I want to remove index.php from URL inside the subdirectory.

1. How could I perform it through web.config ?

2. How could I perform it through .htaccess ?

I found THIS, but got no answer.

3
  • Ok so what server are you running. A linux apache server or the other kind... :) Commented Oct 14, 2016 at 1:29
  • @TimBrownlaw Thanks for your reply. Currently I am using IIS server (this is why my code snippet shows the web.config file.) but I have to apply this in Linux server also. Commented Oct 14, 2016 at 15:16
  • When you access the administration application are you going to be using a url like /admin ? i.e. it has to be something different to anything used in the main application. Commented Oct 19, 2016 at 8:41

6 Answers 6

3

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

Sign up to request clarification or add additional context in comments.

2 Comments

In which web.config file do we have to make above change? In admin subfolder or in main root folder?
In the root folder
1

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 On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ 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.

Comments

1

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>

Comments

0

Edit in htaccess file...which will remove index.php from your url.

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /projectname
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
</IfModule>

Comments

0

1) create a file name= .htaccess in application root. add the following code in .htaccess file.

RewriteEngine on
RewriteCond $1 !^(index\.php)
RewriteRule ^(.*)$ index.php/$1 [L]

2) goto application->config->config.php.

replace $config['uri_protocol'] = 'REQUEST_URI';

with this one

$config['uri_protocol'] = 'AUTO';

Comments

0
    1.Go to **"application/config/config.php"** then Edit
     $config['index_page'] = "index.php" 
     To 
     $config['index_page'] = ""
     AND
     $config['uri_protocol'] ="AUTO"
     to
     $config['uri_protocol'] = "REQUEST_URI"

    2.Now go to Root directory not Inside */application* then create file with file name .htaccess and paste the bellow code and save the file.

    RewriteEngine on
    RewriteCond $1 !^(index\.php|resources|robots\.txt)
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L,QSA] 

    3.Now you have to enable your server rewrite_mode/rewrite_module, so search for it in google For your LAMP/WAMP server...

    4.restart your server

You nailed it bro, Now everything is done...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.