【问题标题】:Web Config file for a codeigniter applicationcodeigniter 应用程序的 Web Config 文件
【发布时间】:2016-09-21 12:59:08
【问题描述】:

我遇到了一个没有为我的 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';`

【问题讨论】:

  • 你使用什么样的网络服务器?通常使用 .htaccess 文件。为什么使用 XML?
  • @Clemenz 它是一个 Windows iis 7.0 服务器而不是 apache,这就是我必须使用 web.config 的原因。
  • 只是一个简单的谷歌搜索结果。你试过这个吗? stackoverflow.com/questions/9965124/… 似乎您在配置中错过了一些正则表达式。
  • 是的,我也试过了。 @克莱门茨
  • 这个怎么样?我对IIS一无所知。所以我不知道你是否有管理面板。 phreek.org/blog/2010/06/codeigniter-url-rewriting-on-iis-7(注意最后一项,更改您的 CodeIgniter 配置 index_page 设置!)

标签: php codeigniter iis web-config


【解决方案1】:

您是否尝试过这里提到的这种方法

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 相同,也有许多在线转换器,您可以尝试一下

【讨论】:

    【解决方案2】:

    对于您的配置文件,try this article。您的问题似乎在您的行动路线上。

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

    将其更改为:

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

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

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

    这更具体一些,以后可能会避免一些头痛。

    【讨论】:

      【解决方案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>
      

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

      谢谢

      【讨论】:

        【解决方案4】:

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

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

            <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 等设置也很重要。如果有其他帮助写您的评论。

        【讨论】:

          【解决方案5】:

          首先我们需要从 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/

          【讨论】:

          • 主要问题是我无法使用 .htaccess,因此它是 IIS 服务器而不是 Apache。
          猜你喜欢
          • 1970-01-01
          • 2019-12-13
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2019-11-09
          • 1970-01-01
          相关资源
          最近更新 更多