Php codeigniter应用程序的Web配置文件

Php codeigniter应用程序的Web配置文件,php,codeigniter,iis,web-config,Php,Codeigniter,Iis,Web Config,我的web配置文件无法重写codeigniter应用程序的url。这是web配置文件 <?xml version="1.0" encoding="UTF-8"?> <configuration> <system.webServer> <rewrite> <rules> <rule name="Clean URL" stopProcessing="true">

我的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>
下面是我更改的config.php设置

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

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

因此,在route.php中,您将更改该行

$route['default_controller'] = "welcome";
$route['404_override'] = 'notfound';
$config['uri_protocol'] = 'AUTO';
config.php中,您将更改该行

$route['default_controller'] = "welcome";
$route['404_override'] = 'notfound';
$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> 

通过

您尝试过这里提到的方法吗

这里也提到了

在URL重写部分下。它具有与我使用的相同的.htaccess,也有许多在线转换器,您可以尝试一下配置文件。看来你的问题在你的行动路线上

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

改为:

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

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

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

这一点更为具体,可能会避免以后出现一些令人头痛的问题。


<?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>
你可以试试这个代码,它会很好,我也只使用这个代码


谢谢

我在使用mssql、windows server和codeigniter平台时也遇到了问题。从url中删除index.php对我来说太难了,或者你可以说是漂亮的url。经过多次讨论和研发。我在服务器根目录下的webcofig文件中做了一些更改

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


//默认代码。。
//另一个默认代码

确切地说,它的工作和剩余部分的codeigniter工作良好。同样重要的是在routes.php和config.php中设置默认url等设置。如果有人帮你写评论。

你使用什么样的Web服务器?通常使用.htaccess文件。为什么要使用XML?@Clemenz这是一个Windows iis 7.0服务器,而不是apache,这就是为什么我必须使用web.config。只是一个简单的google结果。你试过这个吗?似乎你的配置中遗漏了一些正则表达式。是的,我也尝试过@克莱门茨这个怎么样?我对IIS一无所知。所以我不知道你们是否有管理小组。(注意最后一项,更改CodeIgniter配置索引页面设置!)主要问题是我无法使用.htaccess,因此它是IIS服务器而不是Apache。
    <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>