Home > OS >  Rewrite condition htaccess to web.config
Rewrite condition htaccess to web.config

Time:08-05

I would like to understand how the following htaccess file conditions translate for the web.config:

RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1 [L,QSA]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s(.*)/index\.php [NC]
RewriteRule ^ %1 [R=301,L]

CodePudding user response:

You can convert htaccess conditions automatically by using the IIS URL Rewrite Module, you can find the explanation here.

This are your rules converted:

<rewrite>
      <rules>
        <rule name="Imported Rule 1" 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 2" stopProcessing="true">
          <match url="^" ignoreCase="false" />
          <conditions>
            <add input="{THE_REQUEST}" pattern="^[A-Z]{3,}\s(.*)/index\.php" />
          </conditions>
          <action type="Redirect" redirectType="Permanent" url="{C:1}" />
        </rule>
      </rules>
    </rewrite>
  • Related