Question

I use IIS Rewrite Module. I have a few static files, and they are stored at

website/static/xyz/abc

I added IIS Rewrite rule as follows:

regular expression pattern:

xyz/.+

rewrite URL:

/static/{R:0}

First, if I type (with an ending /)

http://mysite/xyz/abc/

everything seems working just fine. The browser address bar shows exactly what I typed.

Second, If I type (without the ending /)

http://mysite/xyz/abc

the website still displays the content correctly, but the browser address bar changes to (by adding static and the ending /)

http://mysite/static/xyz/abc/

How can I make IIS not show /static in the second situation?

Thanks and regards.

UPDATE

Regular expression is used.

            <rule name="inauguralball">
                <match url="inauguralball(/.*)?" />
                <action type="Rewrite" url="/static/{R:0}" />
            </rule>
Was it helpful?

Solution

I think I found your answer here: http://support.microsoft.com/kb/298408/EN-US. When you leave out the trailing slash and IIS finds a directory that matches your request, it performs a redirect for you. I believe this is where your redirect is coming from, thereby sending you to /static/inauguralball/. Notice that IIS has also added the trailing slash for you because it detected that directory exists.

Can you make sure that your hrefs always point to /inauguralball/ (with the trailing slash) so that IIS doesn't perform that automatic redirect for you?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top