I use IIS 7.5 and URL Rewrite.
I have a website with the following file hierarchy:
webroot
webroot/LegacySite
Both webroot/ and legacy/ are separate App-Folders in IIS.
I need to rewrite my URLs so:
Below my Web.Conf
(in the webroot folder) does not work properly, could you point out what I'm missing?
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="MyRole" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^mysite.com" />
<add input="{PATH_INFO}" pattern="^\LegacySite\" negate="true" />
</conditions>
<action type="Rewrite" url="\LegacySite\{R:0}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
The following should work:
<rule name="MyRole" stopProcessing="true">
<match url="LegacySite/(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^mysite.com$" />
</conditions>
<action type="Rewrite" url="/{R:1}" appendQueryString="true" />
</rule>
You might want to drop the conditional for checking the host name. Is that really important? Do you have any other domain names bound to that website for which you don't want the redirect to happen? It seems unnecessary. You probably only need:
<rule name="MyRole" stopProcessing="true">
<match url="LegacySite/(.*)" />
<action type="Rewrite" url="/{R:1}" appendQueryString="true" />
</rule>
I've added appendQueryString="true"
to pass any (optional) query string parameters to the rewritten URL.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With