Need help with this Regex + UrlRewriter.NET please :)

257 Views Asked by At

Previously, on StackOverflow ...

(Summarized)

I need to capture all requests, for a particluar subdomain .. and rewrite their destination.

Now, the trick to determining the host via regex was solved.

Now, i need to make sure all requests to the root index page is rewritten, but i can't figure out the correct regex to find the 'homepage' / website root.

this is what i have....

<if header="HTTP_HOST" match="^foo\.mydomain\.com\.au(?::\d+)?/?$">
    <!-- snip some other rewrites, eg./buying/product -> ~/Pages/Foo/Bar.aspx -->
    <rewrite url="^/$" to="~/Pages/SomeWeirdFolder/Home.aspx" processing="stop"/>
</if>

Now if one of the rewrites were not found, then it falls through and continues.

So .. can anyone please help?

UPDATE

I've also tried "^$", "^~/$", "^~?/?$" ... with no luck.

3

There are 3 best solutions below

1
On

Does this work?

<rewrite url="^/?$" to="~/Pages/SomeWeirdFolder/Home.aspx" processing="stop"/>
<!-- -----------^ -->
1
On

Can you elaborate on what you are trying to match. If the text that you are matching only contains "/" then what you have should match (unless you need to escape /, like /). However if what you are trying to replace is the leading "/", as in /foo/bar/ with ~/MyPath/foo/bar then we need to account for the characters after the first "/"

0
On

I found out the problem.

The root directory of the site is noit '/', is was the file the default document is being set to .. in this case '/default.aspx'

after that, it all worked :)