IIS7 Rewrite Module - Redirct from root to default.aspx - iis-7

I have a situation where I need to rewrite from the root to default.aspx. So if someone hits www.domain.com or www.domain.com/ I need to redirect to www.domain.com/default.aspx - any idea what the regex for this looks like and which server variable to regex on?
When I run a trace and I visit www.domain.com/ or www.domain.com it always shows the SCRIPT_NAME and other similar server variables to have a value of /default.aspx - however this does not work in the rewrite module. E.g. when someone visits www.domain.com/ or www.domain.com the SCRIPT_NAME is still /default.aspx - so it doesn't seem to pick up that they visited the non default.aspx page.

I solved this by using a Url Rewrite map (part of the rewrite module), I was able to redirect from / to /default.aspx. As a rule before the rewrite map I make sure that all requests are redirected to an ending slash.

I had a similar problem and I think it really sucks that IIS hides the URL from you and only gives you the name of the script, which you already know. It was worse in earlier versions of IIS, because it forgot to copy the query string. I had to work around that by not defining any default document at all, and making the error page for directory listing denied redirect to the script. I guess the same thing would work here.

Related

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

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?

Redirect issues

Whoever wrote the navigation for the site I’m currently working on (classic asp) points the navigation links to a folder, then inside to folder has an index.asp file, so the urls will look something like this www.mysite.com/myfolder/mysubfolder
Now, when watch the page load using httpfox, I notice that the first entry is a 302 redirect to the same address with a “/” on the end, so www.mysite.com/myfolder gets redirected to www.mysite.com/myfolder/ (note the / on the end).
I’m not to worried that it’s a 302 since its in the admin section of the site, but when I forward the host headers from ISA server, for an https request, its being redirected from https://www.mysite.com/myfolder to http://www.mysite.com:443/myfolder/ and causing all kinds of problems.
Anyway, I can’t seem to find any code making this redirect happen, so does IIS 6 do this because the url points to a folder? Or do I need to comb through the code more closely?
the problem is not in the code.
the redirect happens because there is no url "https://www.mysize.com/myfolder".
correct urls look like this: "https://www.mysize.com/myfolder/"
so the last / is important and only with this you have a valid url!
the webserver now is cute enough to automatically send a "302 found (originally temporary redirect, but now commonly used to specify redirection for unspecified reason)" status code.
just add the / to the links and you're fine

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.

Subdomain to point to subdirectory of main site?

I have my website running at:
www.example.com
I also have this other domain:
www.example.net
Is it possible to point "www.example.net" to a subdirectory of "www.example.com"? For example:
www.example.net-> www.example.com/other
?
It's not just a redirect, I need to serve the pages and see "www.example.net" in the user's browser.
What do you think?
We use IIS7 and everything is ASP.NET (aspx pages, ascx controls, etc).
Using ISAPI Rewrite
[ISAPI_Rewrite]
RewriteCond Host: (?:www\.)?other\.com
RewriteRule (.*) http://www.domain.com/other$1 [I,L]
You're looking at two methods for this:
URL rewriter
Server.Execute method
The first is a httpmodule that silently redirects the request without changing the url in the address bar, the second is a method you can call within aspx code. I think the latter is only good though if you're working in the same application, so I would go with the URL rewriter.
There is an official iis7 URL rewriter available on www.iis.net afaik.
-Oisin
Two questions for you:
Can you set them up as two different web sites in IIS?
If someone visited example.net/page.htm, would that be the same as example.com/other/page.htm?
If the answer is yes to both of those, why not just setup a new web site in IIS and point it to the "other" file path.

Resources