如何使用IIS 8.0服务器从url(Code Igniter)中删除index.php

时间:2018-03-13 21:33:35

标签: php codeigniter iis codeigniter-3

我下载了Code Igniter 3.1.7并在IIS 8上托管我的网站。但是;由于我一直试图解决的一个恼人的问题,我目前处于停止状态。

我的目标是删除' index.php'尝试访问控制器时从url。

  

示例:http://localhost/welcome而不是   http://localhost/index.php/welcome

由于IIS不使用htaccess文件创建规则来删除' index.php'来自网址。我尝试的另一种方法是使用IIS提供的URL Write附加组件。

enter image description here

点击应用后。创建了web.config文件:

<?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="{R:1}" pattern="^(index\.php|assets|images|js|css|uploads|favicon.png)" ignoreCase="false" negate="true" />
                        <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}" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

然后我去了application / config / config.php文件并更改了这些变量:

$config['base_url'] = '';$config['base_url'] = 'http://localhost/';   $config['index_page'] = 'index.php';$config['index_page'] = '';

之后,我尝试使用http://localhost/welcome进行访问,但我收到此消息:

  

404 - 找不到文件或目录。您正在寻找的资源   可能已被删除,更改名称或暂时   不可用。

4 个答案:

答案 0 :(得分:0)

试试这个

在你.htaccess档案

RewriteEngine On

RewriteBase /your_subfolder

RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]

RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ index.php?/$1 [L]
application/config/config.php

中的

$config['index_page'] = '';

<强>更新 抱歉,我没有看到您使用IIS 8.0服务器

请参阅:https://docs.microsoft.com/en-us/iis/application-frameworks/install-and-configure-php-applications-on-iis/translate-htaccess-content-to-iis-webconfig

答案 1 :(得分:0)

首先在app / config / autoload.php中设置您的URL Helper curl -L -b /path/to/cookies.txt {url}

然后在此处设置您的基本网址,例如$autoload['helper'] = array();像这样

$config['base_url'] = ''

OR

$config['base_url'] = 'http://localhost/example_project'

现在运行您的应用$root=(isset($_SERVER['HTTPS']) ? "https://" : "http://").$_SERVER['HTTP_HOST']; $root.= str_replace(basename($_SERVER['SCRIPT_NAME']), '', $_SERVER['SCRIPT_NAME']); $config['base_url'] = $root; //$root is your codeigniter project name i.e. eCommerce, example_project

答案 2 :(得分:0)

首次确保$config['index_page] = '';

之后尝试此.htdocs

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ index.php/$1 [L]

答案 3 :(得分:0)

 Index.php remove and HTTP to https redirect in CodeIgniter. make 
 web.conig file and put code.


 <?xml version="1.0" encoding="UTF-8"?>
   <configuration>
      <system.webServer>
          <httpErrors errorMode="Detailed" />
               <asp scriptErrorSentToBrowser="true"/>
               <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>
   <!-- redirect non http to https  -->
  <rule name="www redirect" enabled="true" stopProcessing="true">
  <match url=".*" />
  <conditions>
    <add input="{HTTP_HOST}" pattern="^[^\.]+\.[^\.]+$" />
    <add input="{HTTPS}" pattern="off" />
  </conditions>
  <action type="Redirect" url="https://www.{HTTP_HOST}/{R:0}" />
 </rule>
 <rule name="www redirect https" enabled="true" stopProcessing="true">
  <match url=".*" />
  <conditions>
    <add input="{HTTP_HOST}" pattern="^[^\.]+\.[^\.]+$" />
    <add input="{HTTPS}" pattern="on" />
       </conditions>
      <action type="Redirect" url="https://www.{HTTP_HOST}/{R:0}" />
     </rule>
      <!-- redirect non http to https  -->
    </rules>
   </rewrite>
    </system.webServer>

   <system.web>
      <customErrors mode="Off"/>
      <compilation debug="true"/>
   </system.web>