问题 codeigniter应用程序的Web Config文件


我正在遭受一个Web配置文件,该文件没有重写我的codeigniter应用程序的url。这是web配置文件。

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

这是我的网站: http://gandhitomodi.com

我无法得到这种网址 http://gandhitomodi.com/controller/method/

例如

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

请帮我解决这个问题。

****编辑*****

这是route.php

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

这是我已经更改的config.php设置。

$config['base_url']="http://gandhitomodi.com/";
$config['index_page']='';
$config['url_protocal']='PATH_INFO';`

3644
2017-09-21 12:59


起源

你使用什么样的网络服务器?通常使用.htaccess文件。为什么要使用XML? - Fjarlaegur
@Clemenz它是一个窗口iis 7.0服务器而不是apache,这就是为什么我必须使用web.config。 - Dhaval Purohit
只是一个简单的谷歌结果。你试过这个吗? stackoverflow.com/questions/9965124/...  好像你错过了配置中的一些RegEx。 - Fjarlaegur
是的,我也尝试过。 @Clemenz - Dhaval Purohit
这个怎么样?我不了解IIS。所以我不知道你是否有管理小组。 phreek.org/blog/2010/06/codeigniter-url-rewriting-on-iis-7(注意最后一项,更改CodeIgniter配置index_page设置!) - Fjarlaegur


答案:


你在这里提到过这种方法吗?

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

这里也提到了

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

在URL重写部分下。它具有相同的.htaccess,我正在使用也有许多在线转换器,你可以尝试


6
2017-09-26 06:34





对于您的配置文件, 试试这篇文章。您的问题似乎就在您的行动方面。

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

改为:

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

问号导致您的问题。此外,您的匹配行可能会更改为:

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

这有点具体,可能会在以后阻止一些令人头疼的问题。


2
2017-09-26 14:09





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

你可以试试这个代码它会工作正常我也只使用这个代码

谢谢


2
2017-09-28 15:44





当我使用mssql和windows server以及codeigniter平台时,我也遇到了问题。我很难从url中删除index.php,或者你可以说漂亮的网址。经过大量的讨论和研发。我在服务器的根目录下对webcofig文件进行了一些更改。

重写web配置的规则以删除index.php是 :

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

肯定它的工作和codeigniter的其余部分工作正常。在routes.php和config.php中设置默认URL等设置也很重要。如果有任何其他帮助写下您的评论。


2
2017-09-30 08:03





首先,我们需要从url中删除index.php

所以 route.php 你会改变这条线

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

并在 config.php文件 你会改变这条线

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

之后你需要添加 的.htaccess 文件在网站的根目录中,如下所示:

/application
/system
/assets
/.htaccess

并将此代码添加到 的.htaccess 文件

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> 

然后,您可以像控制器一样访问控制器中的方法

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

通过 http://gandhitomodi.com/reviews/latest/


0
2017-09-25 12:20



有一个主要的问题,我不能使用.htaccess因此它是一个IIS服务器而不是Apache。 - Dhaval Purohit