ReWrite rule for IIS 7+ - asp.net

I have a site that generates the following url structure that I would like to rewrite.
current url
domain.com/Store/catid/20/prodId/50/pair-of-socks.aspx
desired url
domain.com/pair-of-socks.aspx

It really depends on how many edge cases you need to cater for. A simple solution would be:
Match URL (\w+/)+(\w+.\w{3,4})
Rewrite URL {R:2}

Related

IIS - Rewriting URL with %2520

I am trying to rewrite a URL with "%2520" in the path, to another URL.
The URL looks like this:
"www.example.com/this%2520url/index.html"
I tried several different RegEx methods, but with no success yet.
I'm using IIS 7 with the URL rewrite module.

Regex on URL rewrite module

I need a help with Regex on URL rewrite module.
I want to apply a rule for the home page.
I tried with ^default.aspx, which is working fine when user access the site with /default.aspx
But normally users are accessing the site with / (www.website.com/) so I am trying to write the reqex and not able to find the correct one.
I tried lot of different combination but nothing worked so far.
^(/default.aspx|$|/$)
^(|/|/default.aspx)
Thanks for the help
You could use the following pattern:
^(/|default.aspx)?$
It will match /, default.aspx or nothing

Extensionless url rewriting / filtering url rewrites

I've done some url rewriting, always using the Intelligencia.UrlRewriter and it always worked fine. But now i want to achieve the following and somehow i can't get it right.
i want:
www.mydomain.com/products/books > rewrite to www.mydomain.com/products.aspx?id=books
this works fine, because i can set my criteria to /products/..
www.mydomain.com/mybook > rewrite to www.mydomain.com/productdetails.aspx?id=mybook
and of course i want www.mydomain.com/newbooks.aspx to function normally
and these last 2 don't work together.
is there a way i can tell my rewrite rule to only rewrite when there is no extension in my url? or is there an other trick?
Thanks in advance!
Well, a bit off the road, but try using ASP.NET Routing instead of URL Rewriter.
I was playing (and messing up) with the rewriter, and here on Stackoverflow I was advised to use Routing, and it is MUCH better (and easier when you get it).
You'll need some little changes to your ASPX files though, but very small.
I thought i'd solve this old, unanswered question. The problem with the extensionless urls turned out to be some configuration problem in IIS. Our system admin fixed this by allowing these urls and after that the rewriter had no problems picking up and translating the URLS.

IIS 7 URL Rewrite doesn't work if the url has a question mark in it

I'm using the URL rewrite feature of IIS7
I'm trying redirect a URL like this
example.com/?parameter=abc
to a URL like this
example.com/somedirectory
the URL redirect works well if the source URL doesn't contain a question mark in it.
pls help
-Vivek
IIS7 redirects don't by default match query strings in the pattern so you have to add a condition as well as the pattern with {QUERY_STRING} matches the pattern parameter=abc

IIS7 URL Rewrite with dynamic subdomains

My goal is to implement the following scheme using the subdomain and path as attributes:
Use a wildcard DNS entry that routes any subdomain to the root site:
Example:
*.example.com
ex: http://xyz.example.com
to
http://example.com
Next I want to rewrite the requests to point to a specific page, passing both the subdomain and the request path as attributes.
Example:
http://xyz123.example.com/images/header.jpg
to
http://example.com/get.aspx?id=xyz123&path=/images/header.jpg
I've seen several questions on here regarding similar goals, but not quite the same. I'm new to using rewrite rules, so any help is appreciated. I will update this as I make progress.
for IIS7, url rewrite functionality is built-in. Rules are set in web.config. For IIS6 you need an ISAPI dll that does the same for you. Use IIRF, it works just fine.

Resources