views:

39

answers:

3

I've a website composed by some .asp file and a lot of static .html

I want to redirect all

www.oldsite.tld/abc.html

www.oldsite.tld/xyz.html

to

www.newsite.tld/abc.html

www.newsite.tld/xyz.html

If I'm on Apache I would use a .htaccess but how could I do that on a ASP, ASP.NET server? (I don't have access to IIS manager)

.NET Fw: 3.5 OS: Windows 2003 IIS: 6.0

A: 

You can do this with global.asax

If this is a permanent redirect then you will want to use a 301 redirect rather than a 302 to allow search engine crawlers to update their links.

Response.Clear();
Response.Status = "301 Moved Permanently";
Response.AddHeader("Location","http://www.newsite.tld/abc.html");
Response.End();

Edit: *You can't do this if the pages are html and not handled by the ASP.NET ISAPI filter, you can configure this through IIS manager but you stated that you don't have access.*

For ASP you could use the predecessor to global.asax - global.asa

For the HTML you are probably stuck with a meta refresh.

Chris Diver
Except for the part where the global.asax won't be executed for plain .html files.
Chris Lively
Unless you configure the web server to do so, but good point without access to IIS manager its unlikely.
Chris Diver
+2  A: 

Try this in your web.config file:

<rule name="Redirect Rule" stopProcessing="true"> 
<match url=".*/(.*)" />
<action type="Redirect" url="www.newsite.tld/{R:1}" redirectType="Permanent" /> 
</rule>
SageNS
I don't think that works with IIS 6
Chris Diver
I don't have a web.config file in my root folder. The web.config has to contain only that lines? Because it doesn't functions as is.
Riccardo
A: 

If you're using classic ASP...In your global.asa file...you can add code that redirects all requests for .asp files to your new site.

If you're using ASP.NET, you can add code in your global.asax file, Session_Start method that redirects the user.

For your html pages, since they aren't run by the ASP and ASP.NET engine, you'll have to replace them all with a blank html page that only has a meta refresh tag to the new domain & page.

If you have access to the IIS, you can change the 404.htm file that it uses. Add a meta refresh tag to it so all other requests are sent to your site as well.

Ed B