Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to exclude a directory with IIS URL rewriting?

I have a domain.com/index.php and a friendly url rule to redirect domain.com/index.php?s=? requests. I use IIS webserver with the URL rewrite add-on.

Above works fine. However, there is a problem with requests to the admin directory...

I also have domain.com/admin/cloud/index.php, which is sometimes needed to obtain or send data (via Ajax). When the rule is active the data is not available, when I delete the above rule then the data is available.

How can I use above url rule and exclude all other requests inside (or to) domain.com/admin/.. ?

This is my current rule-set:

<rule name="RedirectUserFriendlyURL1" stopProcessing="true">
    <match url="^index\.php$" />
    <conditions>
        <add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" />
        <add input="{QUERY_STRING}" pattern="^s=([^=&amp;]+)$" />
    </conditions>
    <action type="Redirect" url="{C:1}" appendQueryString="false" />
</rule>
<rule name="RewriteUserFriendlyURL1" stopProcessing="true">
    <match url="^([^/]+)/?$" />
    <conditions>
        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
    </conditions>
    <action type="Rewrite" url="index.php?s={R:1}" />
</rule>

I tried many ways, including path info... but without success. Maybe someone can give a hint?

Thanks!

like image 670
Arjen Avatar asked Dec 20 '13 17:12

Arjen


People also ask

How do I fix the URL Rewrite module in IIS?

IIS Rewrite Module ProblemUninstall the Rewrite Module from Windows Features. Go to the Web Platform Installer. Pick Url Rewrite from Products | Server section and install. Restart IIS.

Where are IIS rewrite rules stored?

url rewriting - IIS Rewrite rule is stored in XML file that is deleted upon Web Publish - Stack Overflow. Stack Overflow for Teams – Start collaborating and sharing organizational knowledge.


1 Answers

Taking a look here you could add this rule so when a request that you don't want to process comes, you can ignore it and stop processing.

It should be placed first so that this rule executes before the other two.

<rule name="block" stopProcessing="true">
    <match url="^admin/cloud/index.php$" />
    <action type="None" />
</rule>
like image 69
Tasos K. Avatar answered Sep 22 '22 01:09

Tasos K.