: Web.config to redirect except some given IPs I'm looking for a web.config which is equivalent as the .htaccess file below. <IfModule mod_rewrite.c> RewriteEngine on RewriteCond %{REMOTE_HOST}
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.
More posts by @Pope3001725
1 Comments
Sorted by latest first Latest Oldest Best
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.
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.