将Apache重写规则转换为IIS web.config

时间:2018-08-30 16:34:55

标签: php .htaccess iis url-rewriting fuelphp

谢谢,但是此答案已解决。我已经能够成功修改规则,因此不需要进一步的指导。


FuelPHP的新手,并继承了使用Fuel的应用程序。我正在尝试通过url-rewrite使用导入将.htaccess转换为web.config,但是由于某些规则未转换而遇到错误。

.htaccess文件

   # Multiple Environment config, set this to development, staging or production
    # SetEnv FUEL_ENV production

    RewriteBase /bbb/

    <IfModule mod_rewrite.c>

      # Make sure directory listing is disabled
      Options +FollowSymLinks -Indexes
      RewriteEngine on

      # NOTICE: If you get a 404 play with combinations of the following commented out lines
      #AllowOverride All
      #RewriteBase /wherever/fuel/is

      # Restrict your site to only one domain
      # !important USE ONLY ONE OPTION

      # Option 1: To rewrite "www.domain.com -> domain.com" uncomment the following lines.
      #RewriteCond %{HTTPS} !=on
      #RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
      #RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

      # Option 2: To rewrite "domain.com -> www.domain.com" uncomment the following lines.
      #RewriteCond %{HTTPS} !=on
      #RewriteCond %{HTTP_HOST} !^www\..+$ [NC]
      #RewriteCond %{HTTP_HOST} (.+)$ [NC]
      #RewriteRule ^(.*)$ http://www.%1/$1 [R=301,L]

      #Remove index.php from URL
      #RewriteCond %{HTTP:X-Requested-With} !^XMLHttpRequest$
      #RewriteCond %{THE_REQUEST}               ^[^/]*/index\.php [NC]
      #RewriteRule ^index\.php(.*)$         $1 [R=301,NS,L]

      # Send request via index.php (again, not if its a real file or folder)
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d

      # deal with php5-cgi first
      <IfModule mod_fcgid.c>
         RewriteRule ^(.*)$ index.php?/$1 [QSA,L]
      </IfModule>

      <IfModule !mod_fcgid.c>

        # for normal Apache installations
        <IfModule mod_php5.c>
            RewriteRule ^(.*)$ index.php/$1 [L]
        </IfModule>

        # for Apache FGCI installations
        # note '?' removed to prevent url appearing in Input::get()
        <IfModule !mod_php5.c>
            RewriteRule ^(.*)$ index.php/$1 [QSA,L]
        </IfModule>

    </IfModule>

已转换规则的XML

<rewrite>
  <!--This directive was not converted because it is not supported by IIS: RewriteBase /bbb/.-->
  <!--This directive was not converted because it is not supported by IIS: RewriteBase /wherever/fuel/is.-->
  <rules>
    <rule name="Imported Rule 1" stopProcessing="true">
      <match url="^(.*)$" ignoreCase="false" />
      <conditions>
        <!--# Multiple Environment config, set this to development, staging or production-->
        <!--# SetEnv FUEL_ENV production-->
        <add input="{HTTPS}" pattern="^on$" ignoreCase="false" negate="true" />
        <add input="{HTTP_HOST}" pattern="^www\.(.+)$" />
      </conditions>
      <action type="Redirect" redirectType="Permanent" url="http://{C:1}/{R:1}" />
    </rule>
    <rule name="Imported Rule 2" stopProcessing="true">
      <match url="^(.*)$" ignoreCase="false" />
      <conditions>
        <add input="{HTTPS}" pattern="^on$" ignoreCase="false" negate="true" />
        <add input="{HTTP_HOST}" pattern="^www\..+$" negate="true" />
        <add input="{HTTP_HOST}" pattern="(.+)$" />
      </conditions>
      <action type="Redirect" redirectType="Permanent" url="http://www.{C:1}/{R:1}" />
    </rule>
    <!--The rule cannot be converted into an equivalent IIS format because of unsupported flags: NS-->
    <rule name="Imported Rule 4" 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" />
      </conditions>
      <action type="Rewrite" url="index.php?/{R:1}" appendQueryString="true" />
    </rule>
    <rule name="Imported Rule 5" stopProcessing="true">
      <match url="^(.*)$" ignoreCase="false" />
      <action type="Rewrite" url="index.php/{R:1}" />
    </rule>
    <rule name="Imported Rule 6" stopProcessing="true">
      <match url="^(.*)$" ignoreCase="false" />
      <action type="Rewrite" url="index.php/{R:1}" appendQueryString="true" />
    </rule>
  </rules>
</rewrite>

我尝试删除3个未转换的规则(并在.htaccess中对其他规则进行了注释),但最终每次都收到一个PDOException“找不到驱动程序”错误。有人可以帮忙改写吗?(抱歉,此问题与之前在堆栈上提出的许多问题很相似)。

预先感谢

0 个答案:

没有答案