Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

I'm looking for a web.config which is equivalent as the .htaccess file below.

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REMOTE_HOST} !^123\.123\.123\.123
RewriteCond %{REMOTE_HOST} !^321\.321\.321\.321
RewriteCond %{REQUEST_URI} !/coming-soon\.html$
RewriteRule (.*)$ /coming-soon.html [R=302,L]
</IfModule>

Which redirects everyone to a coming soon page except for the given IPs. Unfortunately I'm not familiar with IIS.

share|improve this question
1  
I think you want to use {REMOTE_ADDR} instead of {REMOTE_HOST} –  Frank Jun 30 '12 at 23:50
    
Take a look at this brief tutorial: learn.iis.net/page.aspx/496/… –  Frank Jun 30 '12 at 23:51
add comment

1 Answer

Assuming you are using IIS7, what you will want to do is use the IIS URL Rewrite module. With that installed on your server, you can actually import .htaccess mod_rewrite rules directly and it will convert them to the correct syntax and add it to the web.config of your site. Information about that can be found here.

In its raw form, your mod_rewrite rules will be converted to this:

<rewrite>
  <rules>
    <rule name="Imported Rule 1" stopProcessing="true">
      <match url="(.*)$" ignoreCase="false" />
      <conditions>
        <add input="{REMOTE_HOST}" pattern="^123\.123\.123\.123" ignoreCase="false" negate="true" />
        <add input="{REMOTE_HOST}" pattern="^321\.321\.321\.321" ignoreCase="false" negate="true" />
        <add input="{URL}" pattern="/coming-soon\.html$" ignoreCase="false" negate="true" />
      </conditions>
      <action type="Redirect" redirectType="Found" url="/coming-soon.html" />
    </rule>
  </rules>
</rewrite>

You will most likely need to test and tune the rule to meet your needs. I believe it was mentioned in a comment about using {REMOTE_ADDR} instead of {REMOTE_HOST}. I do agree with that if you are looking for a specific IP address.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.