Web Config file for a codeigniter application

放肆的年华 提交于 2021-02-08 12:35:19

问题


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';`

回答1:


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




回答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.




回答3:


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




回答4:


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.




回答5:


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/



来源:https://stackoverflow.com/questions/39617273/web-config-file-for-a-codeigniter-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!