This works a little too well since mypage.aspx contains childnodes. If a user clicks on a link to a childnode of mypage, they get redirected to mypage and not to the childnode itself.
Any way to fix this? :-)
The current querystring url looks like this: mypage.aspx?myquerystring=1234 and I want it to look like this: mypage/1234.
Nope, the mypage/child/1234 to mypage/child?myquerystring=1234 is not needed :-) Only the parent page: mypage.aspx.
I guess there's not really any way to differentiate the two URLs :-/ The querystring value isn't only numbers, it's actually theme-names such as "christmas", "halloween" etc..
Er... if there's no way to differentiate, then I don't see how this is do-able. Unless there's a finite list of themes and you write one rule per theme.
Well, how can we tell that mypage/xmas should be rewritten but mypage/candies should not?
An easy solution would be to prefix your themes... eg mypage/theme/xmas or mypage/xx-xmas...
Otherwise I don't see how you can do it with rewriting.
That being said,
Write a 404 handler, check if you're looking for .../mypage/something, and redirect to .../mypage?q=something there. That way, the children will be handled first, and if no child is found then you fallback on themes...
Or, create an actual child per theme with an internal redirect to mypage.
But... thinking about how routing should evolve... I'd go with a 404 handler.
Writing a 404 handler would be a nifty way of doing it, but time is not with me on this one :-( Morten, your way works perfect! That's what I'm going for :-) Only thing that's left now is to tell the site that a querystring like this: "christmas & fun" is a legal querystring. It gives me this exception:
A potentially dangerous Request.Path value was detected from the client (&).
Is there any way to tell the site that these special chars are o.k? :-)
Anything you put in the request.path needs to be url-encoded. Else you're going to break things. Think of a theme such as "xmas? fun?" => IIS will see the "?" as introducing a querystring.
Querystring URL rewrite rule
Hi all,
I'm trying to use the Url rewriter to rewrite a querystring to a more clean-looking URL. The snippet I'm using is this:
This works a little too well since mypage.aspx contains childnodes. If a user clicks on a link to a childnode of mypage, they get redirected to mypage and not to the childnode itself.
Any way to fix this? :-)
The current querystring url looks like this: mypage.aspx?myquerystring=1234 and I want it to look like this: mypage/1234.
Any help/hint is greatly appreciated!
Thanks in advance.
Do you also want to redirect mypage/child/1234 to mypage/child?myquerystring=1234?
How can we differentiate betweens mypage/1234 and mypage/child? Because 1234 is numbers?
Hi Stephen,
Nope, the mypage/child/1234 to mypage/child?myquerystring=1234 is not needed :-) Only the parent page: mypage.aspx.
I guess there's not really any way to differentiate the two URLs :-/ The querystring value isn't only numbers, it's actually theme-names such as "christmas", "halloween" etc..
So, is this do-able?
Thanks again!
- Bo
Er... if there's no way to differentiate, then I don't see how this is do-able. Unless there's a finite list of themes and you write one rule per theme.
Hi Stephen,
Ouch! That's what I was nervous about. So there's absolutely no way to 'nicefy' a querystring when the node has got any childnodes?
Well, how can we tell that mypage/xmas should be rewritten but mypage/candies should not?
An easy solution would be to prefix your themes... eg mypage/theme/xmas or mypage/xx-xmas...
Otherwise I don't see how you can do it with rewriting.
That being said,
Write a 404 handler, check if you're looking for .../mypage/something, and redirect to .../mypage?q=something there. That way, the children will be handled first, and if no child is found then you fallback on themes...
Or, create an actual child per theme with an internal redirect to mypage.
But... thinking about how routing should evolve... I'd go with a 404 handler.
I would probably do something like this with the urls:
/mypage/t/christmas
Then you can match it in your rewrite with
^~/mypage/t/(.*)
And that would only prevent you from seeing subpages if there is a page named "t".
Still makes the url nicely readable, and lets you have subpages at the same time.
Hey Stephen and Morten,
Writing a 404 handler would be a nifty way of doing it, but time is not with me on this one :-( Morten, your way works perfect! That's what I'm going for :-) Only thing that's left now is to tell the site that a querystring like this: "christmas & fun" is a legal querystring. It gives me this exception:
A potentially dangerous Request.Path value was detected from the client (&).
Is there any way to tell the site that these special chars are o.k? :-)
Thanks again!
Hi Bo,
Technically, I think you need to escape a string like that, e.g. to appear in a QueryString it'd have to be "christmas%20%26%20fun" ...
/Chriztian
Anything you put in the request.path needs to be url-encoded. Else you're going to break things. Think of a theme such as "xmas? fun?" => IIS will see the "?" as introducing a querystring.
See http://msdn.microsoft.com/en-us/library/system.web.httpserverutility.urlencode.aspx
Thanks Chriztian and Stephen :-)
I talked them into using "og" (danish word for "and") instead of the & character. No problem there! So everything works just as it should now.
is working on a reply...