Demolition Architect
Demolition Architect

Reputation: 54

Rewriting Web.config rule applying to all requests

I spent a few hours trying to find a way (I do not really grasp the tangled IIS docs) to make URLS friendly while keeping a single entry point within the public folder. I mean, when the user types:

"localchosy/myproject/route1"

Internally the rule redirects it to:

"localhost/myproject/public/index.php/route1"

The rule I wrote is and that (i thought) work like a charm, is:

    <system.webServer>
      <rewrite>
          <rules>
            <!-- REWRITING INDEX.PHP -->
                <rule name="Default" stopProcessing="true" >
                    <match url="[/^myproject$/]{1}(.*)" />
                    <action type="Rewrite" url="myrpoject/public/index.php" />    
                </rule>
          </rules>
      </rewrite>
  </system.webServer>

Despite the fact that I still need to add https enforcement and block direct access to folders, it did the work (the app is still beta). But, to my surprise, when I wrote

localhost/phpmyadmin

The server redirected rewrited it as

localhost/myproject/public/index.php/phpmyadmin

The irs clearly something I don't understand about those rules. I thought that the "match" tag meant that the rule applied only if there was a regex match, but it clearly isn't the case... In fact, the prefix I am using withing the url attribute inside the match tag is doing nothing... I don't understand.

How can I make the rule to only apply to URLS starting with "myproject"...

PS: CUrrently I have the web.config file inside inetub/wwwroot, at the same elevel of the projects.

Thanks.

Upvotes: 0

Views: 414

Answers (1)

Bruce Zhang
Bruce Zhang

Reputation: 3042

I tested your rule and did some changes. Please try this.

<rule name="Default" stopProcessing="true">
                <match url="myproject/(.*)" />
                <action type="Rewrite" url="myrpoject/public/index.php/{R:1}" />
                <conditions>
                    <add input="{REQUEST_URI}" pattern="myproject/public/(.*)" negate="true" />
                </conditions>    
</rule>

This is the log of Failed Request Tracing. enter image description here

enter image description here

Upvotes: 1

Related Questions