1

I need to capture requests to folders that aren't file folders to be redirected to a default page with the requested path as the querystring.

For example, if the user requests

www.mysite.com/IT

I want it to redirect to

www.mysite.com/default.aspx?q=IT

However, if they request a page that is in a real sub-folder, that shouldn't be redirected. For example, requests to www.mysite.com/projects/new.aspx shouldn't try to do any re-directions as it's a physical folder and file in the site.

2 Answers 2

1

Use the IIS Rewrite module and the set it up in the web.config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <clear />
                <rule name="Redirector" patternSyntax="Wildcard">
                    <match url="*" />
                    <conditions>
                        <add input="{PATH_INFO}" pattern="/*" />
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                    </conditions>
                    <action type="Rewrite" url="/default.aspx?q={PATH_INFO}" appendQueryString="true" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>
Sign up to request clarification or add additional context in comments.

1 Comment

Awesome! That did it
0

You could define a 404 error page that would redirect to your default page with the "q=" that you desire

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.