views:

1308

answers:

5

I'm using the URL Rewriting.NET tool with IIS 6. I've got my default page content set for default.aspx in IIS. What I'm trying to do is have /default.aspx provide a 301 redirect to the root directory (www.example.com/default.aspx -> www.example.com). I've tried turning off default documents, to no avail.

What I'm hoping to do is use a couple of URL Rewriting.NET rules to accomplish this goal. Any thoughts?

EDIT:

Sorry, I forgot to clarify. If I redirect from /default.aspx to / with default documents turned on (I'd like to leave them on) then I get an infinite loop of default -> / -> default

A: 

I'm not sure I understand what the problem is.

Though if you turn off default documents then / will simply point to the directory rather than the default.aspx page.

Leave default documents on and just do a redirect based on whether default.aspx is in the requested url or not.

Spencer Ruport
that would create an infinite loop
MasterMax1313
"do a redirect based on whether default.aspx is in the requested url": if(Request.Url.ToString().ToLower().IndexOf("default.aspx") != -1) response.redirect("/");
Spencer Ruport
This still results in an infinite loop, since default documents are turned on, a request for / turns into a request for /default.aspx
MasterMax1313
not in the headers
Shawn Simon
+1  A: 

If I understand you correctly, you don't want to display 'default.aspx' whenever someone comes into a folder with that document available.

So if they do hit it, you want to automatically redirect to the '/' and just load the default document anyway?

If that's the case then, as stated above, you run the risk of an infinite loop. The second comment gives you an answer but I guess expanding that to the re-write engine what you'd want is to:

Turn off default documents Register each folder with the re-write engine When that folder is requested load the default.aspx file as per your target rule

Does this sound about right?

I have to ask, why do you want to do this?

Simon
I know it's pretty strange, but it's a requirement of the site, for SEO value, so that only one link will take you to default.aspx, rather than two.
MasterMax1313
I've done a fair bit of SEO training and hearing this seems odd. I'd be surprised that a search engine like Google or MSN would penalise you. So I can only guess its so you get all your ranking points for one url.Still - haven't done SEO stuff in a little while so that's just a guess!
Simon
As I understand it, it isn't that there are two pages that serve up the same page, it's that if people link to both example.com and example.com/default.aspx I'm told that it spreads out link value.
MasterMax1313
You are right, 2 pages with the same content is not as good as 1 page:http://www.google.com/support/webmasters/bin/answer.py?answer=66359
BigBlondeViking
A: 

well you can use regular .net to inspect httprequest url, if it has "default.aspx" in it, you can redirect to "/", there will be no infinite loop and you better do this on preload, and end response afterwards, to minimize time it takes to process

Ayyash
sorry, i didnt see the comments in the above answer, hey have the answer alright
Ayyash
+2  A: 

In the end I wound up using IIS 7 with the URL Rewrite module, which allows you to do this redirect properly.

Edit :

The rule is

<rule name="Default Redirect" stopProcessing="true">
    <match url="^default\.aspx$" />
    <action type="Redirect" url="/" redirectType="Permanent" />
</rule>

you can do that with a separate rule for each folder, or you can use

<rule name="All Redirect">
    <match url="^(.*\/)*default\.aspx$" />
    <action type="Rewrite" url="{R:1}" />
</rule>
MasterMax1313
care to share?
Ayyash
I've updated the answer with some code
MasterMax1313
A: 

I had the same problem. For those who wonder why anyone would want to do this, it's a question of SEO. If Google indexes your home page with and without the default.aspx at the end, the PageRank and link popularity will be split between the two URL's. Now, if you're experiencing this problem, and you're able to consolidate the two URL's then you may get a boost in search rankings. One more thing to keep in mind is that if you're going through the trouble, you MUST use a 301 redirect for Google to consolidate their index between two URL's. Otherwise your efforts will be futile.

This is a little too late since you've already solved this by upgrading to IIS7. But I'll just add that the only solution to this problem I've come up with for IIS6 is to add an ISAPI filter.

I documented the complete solution here... http://swortham.blogspot.com/2008/12/redirecting-default-page-defaultaspx-to.html

Steve Wortham