11

I am suffering with a web config file that is not rewrite the url for my codeigniter application. here is the web config file.

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
    <rewrite>
        <rules>
            <rule name="Clean URL" stopProcessing="true">
                <match url=".*" />
                <conditions>
                    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                </conditions>
                <action type="Rewrite" url="index.php?{R:1}" appendQueryString="true" />
            </rule>
        </rules>
    </rewrite>
</system.webServer>
</configuration>

here is my site : http://gandhitomodi.com

i am not able to get this kind of url http://gandhitomodi.com/controller/method/

for example

http://gandhitomodi.com/welcome/index/

Please Help me through this.

****Edited*****

here is the route.php

$route['default_controller']="welcome/index";
$route['sendmail']="welcome/send";

here is the config.php settings that i have changed.

$config['base_url']="http://gandhitomodi.com/";
$config['index_page']='';
$config['url_protocal']='PATH_INFO';`
Dhaval Purohit
  • 1,270
  • 10
  • 28
  • What kind of webserver do you use? Usually a .htaccess file is used. Why use XML? – Fjarlaegur Sep 21 '16 at 13:02
  • @Clemenz it is a window iis 7.0 server not the apache that's why i have to use web.config. – Dhaval Purohit Sep 21 '16 at 13:03
  • Just a simple google result. Have you tried this? http://stackoverflow.com/questions/9965124/how-to-rewrite-the-index-php-of-codeigniter-on-windows-azure Seems you miss some RegEx in your config. – Fjarlaegur Sep 21 '16 at 13:05
  • yes i have also tried that. @Clemenz – Dhaval Purohit Sep 21 '16 at 13:06
  • How about this? I have no knowledge of IIS. So i don't know if you have a management panel. http://phreek.org/blog/2010/06/codeigniter-url-rewriting-on-iis-7 (Note the last item, change your CodeIgniter config index_page setting!) – Fjarlaegur Sep 21 '16 at 13:10
  • Post your config/router.php – Goose Sep 21 '16 at 13:22
  • @Goose i have added the route.php and config.php file. – Dhaval Purohit Sep 21 '16 at 13:43
  • @Clemenz i am not able to try that url because i have not the hosting details only ftp that i have. – Dhaval Purohit Sep 21 '16 at 13:44
  • Last try. I dont have any experience with IIS, so i cant help you further. I am actually googling for you. Something you can do too, so you wont need me haha. http://stackoverflow.com/questions/5408111/codeigniter-2-on-iis-with-web-config-file?rq=1 (its for CI 2 but maybe it will work, check out the comments too) – Fjarlaegur Sep 21 '16 at 14:12
  • It's Ok dude @Clemenz i am searching it for almost 2 days and i am not getting the things done. that's why i have posted this question. and one more thing i have also tried the last before HA HA LOL. – Dhaval Purohit Sep 21 '16 at 15:04
  • Have you tried ``, It removes all rewrite rules for this application. – Ravi Sachaniya Sep 27 '16 at 06:32

5 Answers5

6

Have you tries this method as mention here

https://blogs.msdn.microsoft.com/azureossds/2015/04/23/converting-apache-htaccess-rules-to-iis-web-config-using-iis-manager-for-azure-websites/

also it is mention over here

https://blogs.msdn.microsoft.com/azureossds/2015/09/28/convert-apache-htaccess-to-iis-web-config/

under the URL Rewriting section. It has the same .htaccess which I am using also there are many online converters to whom you can give a try

Vivek Shah
  • 434
  • 3
  • 10
2

For your config file, try this article. It appears that your issue is on your action line.

<action type="Rewrite" url="index.php?{R:1}" appendQueryString="true" />

Change that to:

<action type="Rewrite" url="index.php/{R:1}" appendQueryString="true" />

The question mark is causing your issue. Also, your match line might be changed to:

<match url="^(.*)$" ignoreCase="false" />

That is a bit more specific and might prevent some headaches later on.

Community
  • 1
  • 1
Danny Flack
  • 126
  • 6
2
<?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>

you can try this code it will work fine i am also using this code only

thank you

Abdul Hameed
  • 263
  • 4
  • 19
2

I have also in problem when i was working with mssql and windows server and codeigniter platform. Its so hard for me to remove index.php from url or you can say pretty url . After a lot of disscussion and r&d. I got some changes in webcofig file at root of server.

Rewrite rule for web config to remove index.php is :

    <configuration>
    <appSettings>
         // default code..
    </appSettings>
    <system.webServer>
        <handlers>
            <clear />
// another default code

 </handlers>
        <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> 
    </system.webServer>
</configuration>

Definately its working and also remaining part of codeigniter working fine. Also important thing set default url etc setting in routes.php and config.php . If any another help write your comment.

Kumar Rakesh
  • 2,718
  • 2
  • 18
  • 39
0

First we will need to remove index.php from url

so in route.php you will change the line

$route['default_controller'] = "welcome";
$route['404_override'] = 'notfound';

and in config.php you will change the line

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

After that you will need to add .htaccess file in the root directory of website like this:

/application
/system
/assets
/.htaccess

and add this code to .htaccess file

Header append X-FRAME-OPTIONS "SAMEORIGIN"
Header set Cache-Control "no-store"
Header set X-Content-Type-Options "nosniff"
Header set Strict-Transport-Security "max-age=31536000; includeSubDomains"
ErrorDocument 403 /notfound.php

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L] 


<IfModule !mod_rewrite.c>
        # If we don't have mod_rewrite installed, all 404's
        # can be sent to index.php, and everything works as normal.
        # Submitted by: ollakalla

    ErrorDocument 404 /index.php

</IfModule> 

Then you can access your method in controller like this example

class Reviews extends CI_Controller 
{
    public function latest()
    {
         // Some code here
    } 
}

by http://gandhitomodi.com/reviews/latest/

Ahmed Bermawy
  • 2,290
  • 4
  • 35
  • 42