简体   繁体   中英

How can I convert .htaccess code to web.config?

RewriteEngine On
RewriteCond %{HTTPS} (on)?
RewriteCond %{HTTP:Host} ^(?:www.)(.+)$ [NC]
RewriteCond %{REQUEST_URI} (.+)
RewriteRule .? http(?%1s)://%2%3 [R=301,L]
RewriteCond %{HTTP_Host} ([^.]+).itsprofile.com$ [NC]
RewriteRule (.*) http://itsprofile.com/viewindex.php$1?id =%1 [NC,L]

When you say convert to web.config, I'm going to assume you mean convert .htaccess rewrite rules to IIS URL Rewrite rules. You can find information about importing .htaccess rules to IIS URL Rewrite here .

Your rewrite rules above would be imported and converted to this:

<rewrite>
  <rules>
    <rule name="Imported Rule 1" stopProcessing="true">
      <match url=".?" ignoreCase="false" />
      <conditions>
        <add input="{HTTPS}" pattern="(on)?" ignoreCase="false" />
        <add input="{HTTP_HOST}" pattern="^(?:www.)(.+)$" />
        <add input="{URL}" pattern="(.+)" ignoreCase="false" />
      </conditions>
      <action type="Redirect" redirectType="Permanent" url="http(?{C:1}s)://{C:2}{C:3}" appendQueryString="false" />
    </rule>
    <rule name="Imported Rule 2">
      <match url="(.*)" ignoreCase="false" />
      <conditions>
        <add input="{HTTP_Host}" pattern="([^.]+).itsprofile.com$" />
      </conditions>
      <action type="Redirect" redirectType="Found" url="http://itsprofile.com/viewindex.php{R:1}?id" appendQueryString="false" />
    </rule>
  </rules>

Naturally, you'll want to test all of your rules.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM