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 am moving from an Apache host to IIS. One of my sites in Wordpress (running Multi-site) which give me multiple blogs. I have moved all my rules from my .htaccess to the Microsoft URL ReWrite module. I have one section left that will not import.

I want to restrict access to all instances of the file wp-login.php by Client IP address.

In my .htaccess file I did the following:

<Files wp-login.php>
Order Deny,Allow
Deny from all
Allow from 192.168
</Files>

Any smart ideas on how to accompish this in IIS7.5?

share|improve this question
add comment

1 Answer 1

I found this can be done with URL ReWrite

Credit to: http://www.youtube.com/watch?feature=player_embedded&v=ut0pD2l4z5c#!

from web.config

Be sure to add the ServerVariable you choose (HTTP_X_AdminIPAllowed in my example) to allowed server variables from the URL ReWrite module in the IIS Console.

This example allows access to 192.168.1.* clients to all copies of wp-login.php

<rewrite>
    <rules>
        <clear />
        <rule name="FlagAdminIPs" patternSyntax="ECMAScript">
            <match url=".*" />
            <conditions logicalGrouping="MatchAny" trackAllCaptures="false">
                <add input="{REMOTE_ADDR}" pattern="^192\.168\.1\.(1(2[8-9]|[3-9][0-9])|2([0-4][0-9]|5[0-4]))$" />
            </conditions>
            <serverVariables>
                <set name="HTTP_X_AdminIPAllowed" value="yes" />
            </serverVariables>
            <action type="None" />
        </rule>
        <rule name="Restrict wp-login.php access" enabled="true" stopProcessing="true">
            <match url=".*" />
                <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                    <add input="{REQUEST_FILENAME}" pattern="wp-login.php" />
                    <add input="{HTTP_X_AdminIPAllowed}" pattern="yes" negate="true" />
                </conditions>
            <action type="CustomResponse" statusCode="403" statusReason="Forbidden" statusDescription="Forbidden" />
        </rule>
    </rules>
</rewrite>
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.