Regex on URL rewrite module - asp.net

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

Related

IIS 8.5 URL Rewrite redirection is not working

In IIS 8.5 - Need to URL (framnaes) - https://www.manpowergroup.no/framnaes to new
web site - https://framnes-installasjon.no.
I have tried many pattern and condition. But not working.Could you please help me to fix it.
Sorry! In my previous POst/Answere I am not able to post whole Rule tag.
Anyways here this regular expression "/[^/]+/sub-dir-name" worked for me to find out the specific directory in url and then redirect to another website.
Thanks

Regexing it up with IIS re-write module

I am developing a profile-based web application where each user is assigned there own url through their username & iis rewrite mod's magic. A typical user's profile url would be http://www.mymark.com/mike
Each user is also created a blog in a multi-user wordpress installation. The wordpress url would look like this: http://www.mymark.com/blog/mike
I am trying to use the rewrite module to create more canonical urls for the user (http://www.mymark.com/mike/blog), and have tried several regex variations that I have created through RegExr(a regex generation tool) and come up with this as the pattern to match (www.|)mymark.com/([^/]+)/blog but haven't had any success so far. What am I doing wrong here?
Here is a screen shot of my re-write rule:
The entire host name (mymark.com) is not part of the URL, so you should not enter that as part of the Pattern. To make sure you easily figure it out, make sure to use Failed Request Tracing to extract the exact pattern that you should enter there:
http://learn.iis.net/page.aspx/467/using-failed-request-tracing-to-trace-rewrite-rules/
but its probably going to be something like:
(^/])*/blog

Response.Redirect passes the ISAPI_Rewrite engine

*I use ISAPI_Rewrite v2
Hi,
So I implement ISAPI_Rewrite on my site.
Now i put on my pages a Response.Redirect
But as it seems the redirect passes the ISAPI engine..
i.e. I see the new url but the rule doesnt apply.
for example i enter this:
example.com/SomePage.aspx
in SomePage.aspx.cs - PageLoad function theres:
Response.Redirect("/Page");
So I get redirected to example.com/Page
But it says to me "This link appears to be broken"
on httpd.ini I have this rule
RewriteRule ^/Page$ /Page.aspx [L]
My guess is that the Response.Redirect doesnt go through
the ISAPI_Rewrite...
How can I fix this??
Thanks
=====
edit:
solved, the hebrew chars was the problem, you need to encode them first.
if you do response.redirect the whole page life cycle is working. All the modules are called as usual. So maybe the rewrite module does not get called?
Did you put some breakpoints in the module so that you know if it gets called or not?
have you set up your module somewhere in your webapp?

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.

ASP.NET Web Dev: Map one directory to another?

We are thinking of renaming our web directory schema to be more user friendly. However, we need any URL requests for the old directory structure to forward to the new one. so....
How do I forward requests for all of these:
http://mydomain.com/OLDdirname/
http://mydomain.com/OLDdirname/samesubdir/
http://mydomain.com/OLDdirname/samesubdir/samescript.aspx
to each of these respectively:
http://mydomain.com/NEWdirname/
http://mydomain.com/NEWdirname/samesubdir/
http://mydomain.com/NEWdirname/samesubdir/samescript.aspx
Any suggestions and perhaps some general guidance as far as gotchas?
You can use a number of things to do something like this. Basically, you're doing URL Rewriting. One of these products should help you get the job done:
ISAPI Rewrite
IIS Rewrite
opURL
IIRF
I use IIRF on many of my websites, and it has always worked without failing. You use regular expressions to define the rules, and it takes care of the rest. It would be extremely easy to setup a few redirects using IIRF.
http://cheeso.members.winisp.net/IIRF.aspx

Resources