17

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!

3
  • Hello, you provide two rules here. Which rule is the one that messes up the /admin/cloud/index.php request?
    – Tasos K.
    Dec 24, 2013 at 7:38
  • Good question. I have no idea. It seems that IIS or the URL rewrite module messes up requests. I have now split the rules: 1) check if it contains "cloud" and 2) the check if it has to rewrite to index.php (thus from friendly url to internal url). The first rule stops processing if the check is valid (in that case the second rule is not nesassary)... for some reason the first check is not the solution to bypass the problem. [..]
    – Arjen
    Dec 24, 2013 at 12:59
  • [..] With only the second rule, the friendly url is working but not the admin part. With only the first rule the admin section is working but not the friendly url part. Sometimes, it does work... but after a few minutes or hours the solution with two separated rules does not work anymore. I don't know where to find the "real problem".
    – Arjen
    Dec 24, 2013 at 13:01

1 Answer 1

37

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>
3
  • @Shahdat These rules are applied before the request hits the ASP.NET engine, so it should work. Consider posting a question and put the link here so that I can take a look.
    – Tasos K.
    Apr 12, 2016 at 16:37
  • 1
    @Tasos I just figured it out. I had to change action type to CustomResponse <action type="CustomResponse" statusCode="403" statusReason="Forbidden: Access is denied." statusDescription="You do not have permission to view this directory or page using the credentials that you supplied." />
    – Shahdat
    Apr 12, 2016 at 16:50
  • 1
    Thank you. you saved my day, i was tried many ways but not included in the first place. Thanks Oct 4 at 7:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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