【问题标题】:how to remove index.php file from url in codeigniter?如何从codeigniter中的url中删除index.php文件?
【发布时间】:2014-09-10 13:08:48
【问题描述】:

我正在尝试从我的网址中删除 index.php,但我很困惑我在 .htaccess 文件中使用了哪些代码,以及我必须对 codeigniter 中的相关文件进行哪些更改。

【问题讨论】:

标签: php codeigniter


【解决方案1】:

只需使用这个 .htaccess

RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

取自here

【讨论】:

    【解决方案2】:

    将这一行添加到您的 htaccess 文件中:

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

    【讨论】:

      【解决方案3】:

      如果您使用的是 IIS,请尝试 importing these rules 到您的 web.config 文件:

      <?xml version="1.0" encoding="UTF-8"?>
      <configuration>
      <system.webServer>
          <rewrite>
              <rules>
                  <rule name="Rule 1" stopProcessing="true">
                      <match url="^(.*)$" ignoreCase="false" />
                      <conditions logicalGrouping="MatchAll">*
                          <add input="{URL}" pattern="^system.*" ignoreCase="false" />
                      </conditions>
                      <action type="Rewrite" url="index.php?/{R:1}" appendQueryString="false" />
                  </rule>
                  <rule name="Rule 2" stopProcessing="true">
                      <match url="^(.*)$" ignoreCase="false" />
                      <conditions logicalGrouping="MatchAll">
                          <add input="{URL}" pattern="^application.*" ignoreCase="false" />
                      </conditions>
                      <action type="Rewrite" url="/index.php?/{R:1}" appendQueryString="false" />
                  </rule>
                  <rule name="Rule 3" stopProcessing="true">
                      <match url="^(.*)$" ignoreCase="false" />
                      <conditions logicalGrouping="MatchAll">
                          <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
                          <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
                      </conditions>
                      <action type="Rewrite" url="index.php?/{R:1}" appendQueryString="false" />
                  </rule>
              </rules>
          </rewrite>
      </system.webServer>
      

      【讨论】:

        猜你喜欢
        • 2012-08-10
        • 2015-10-24
        • 2012-12-19
        • 1970-01-01
        • 2013-10-04
        • 1970-01-01
        • 1970-01-01
        • 2016-05-14
        • 2014-10-28
        相关资源
        最近更新 更多