7

I'm using IIS-7 and am moving a site over from a linux and apache based server environment. I know web.config does the same job as .htaccess. I'm looking to convert the following lines from my .htaccess file to a web.config file. Where would I begin?

Options +FollowSymlinks
RewriteEngine On
RewriteRule ([A-Za-z0-9/_-]+).(jp(e?)g|gif|png)$ thumb.php?src=../../uploads/default/files/$1.$2&size=160x90
Alexander Abakumov
  • 13,617
  • 16
  • 88
  • 129
Dan Lee
  • 684
  • 4
  • 15
  • 35

2 Answers2

22

To convert rules from .htaccess to web.config you can use import feature of the IIS URL Rewrite Module:

  1. go to IIS Manager
  2. click you site in the tree
  3. double-click URL Rewrite in the Feature View
  4. click Import Rules in the Actions panel
  5. paste your .htaccess rules into the Rewrite rules textbox and you'd see your converted rules below.

More info about this feature.

For instance your rules are converted into these ones:

<rewrite>
  <rules>
    <rule name="Imported Rule 1">
      <match url="([A-Za-z0-9/_-]+).(jp(e?)g|gif|png)$" ignoreCase="false" />
      <action type="Rewrite" url="thumb.php?src=../../uploads/default/files/{R:1}.{R:2}&amp;size=160x90" appendQueryString="false" />
    </rule>
  </rules>
</rewrite>
Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
Alexander Abakumov
  • 13,617
  • 16
  • 88
  • 129
  • @DanLee: If my answer was helpful, could you accept and/or upvote it? It has passed more that a year and this thread seems abandoned/useless for further readers unless you give some feedback. – Alexander Abakumov Dec 14 '15 at 16:45
  • 1
    As I don't know about web.config rules, I was searching online converter but you saved my time, thanks to you @AlexanderAbakumov and MS guys. :) – shyammakwana.me Nov 24 '16 at 12:03
0

Just create a web.config file on Notepad or edit the one you have on the root folder and copy and paste this:

<?xml version="1.0" encoding="UTF-8"?> 
  <configuration> 
  <system.webServer> 
    <rewrite> 
      <rules> 
        <rule name="Remove index.php rule" stopProcessing="true"> 
          <match url=".*" ignoreCase="false"/> 
          <conditions> 
            <add input="{URL}" pattern="^/(media|skin|js)/" ignoreCase="false" negate="true" /> 
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> 
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> 
          </conditions> 
          <action type="Rewrite" url="index.php" /> 
        </rule> 
      </rules> 
    </rewrite> 
  </system.webServer> 
</configuration>

reference: https://gist.github.com/sabbour/e49b3ac9e1438c93d5fb

CodingEra
  • 1,313
  • 10
  • 20