We're using IIS7 and ASP.NET 3.5.
We have updated our website with new pages. Now, there are many links on the internet pointing to our website, however many of those links are now broken due to a change in our directory structure for our new website.
I need to have a number of requests, 301 redirected to the "new page." Many of the old pages are simply directory URL's such as:
/services/softwaredevelopment
/products/geographicdata
/sitemap
/company/termsofuse
I have written some code in the Global.asax file to catch the url's, parse them out, and redirect them. However, when there is no file reference (.aspx), the URL's are not caught by my ASP.NET application.
It seems then, that these redirects need to be created in IIS7.
Now, the urls above are at a directory level (they are not directly requesting an actual .aspx page)... I can redirect a 'directory' request to another 'directory' by using virtual directories.... But I cant redirect a directory request to an actual .aspx file
Here are some of the types of redirects I need to make:
==========
Old: /services/softwaredevelopment
redirect to: /services/custom-software-development.aspx
============
Old: /sitemap
redirect to: /sitemap.aspx
============
Old: /company/termsofuse
redirect to: /company/termsofuse.aspx
=============
Old: /company/careers
redirect to: /company/careers.aspx
=============
Old: /services/
redirect to: /services/custom-software-development.aspx
=============
Can someone shed some light on how to accomplish this? Please let me know if you have any questions. Many thanks for your help.
Tim
One quick and dirty option is to create default.aspx redirect pages in the folders you have listed. For example, to handle /services/softwaredevelopment, create a file default.aspx at /services/softwaredevelopment/default.aspx with the following:
<%# Page Language="C#" Inherits="System.Web.UI.Page" %>
<% Response.Redirect("/services/custom-software-development.aspx"); %>
This solution is only practical if there are only a few redirects, as it clutters your project with code files that do very little. A better solution for a large number of redirects is to use IIS 7's native URL rewriter.
Check out "HTTP Redirection in IIS 7 on Windows Server 2008" http://www.trainsignaltraining.com/iis7-redirect-windows-server-2008
You should be able to do most kind of redirect by configuring IIS rather than coding.
Related
My application url is like this.
http://somename/webname/default.asp
It also contains some other default.asp like http://somename/webname/booking/default.asp and some others too. Even if user tries to access other default.asp, I want them to redirect to
http://somename/webname/default.asp.
Update:
I have been checking like this in global.asa.
Application("txtPathInfo") = Request.ServerVariables("PATH_INFO")
if (Application("txtPathInfo") <> "/webname/default.asp") then
Response.Redirect("/webname/default.asp")
end if
But the problem is, first time it is working fine,redirecting to desired page. Next attempt it allows, may be the global.asa is not called while trying to access in same session. Please anyone provide some feasible solution on this. Thanks :)
One quick way is to put this code in a default.asp page in each possible folder.
<%
Response.Redirect "http://somername/default.asp"
%>
If there are too many folders or some of those folders don't physically exist you'll need to use a url rewrite rule or code within a custom 404 error page.
For rewrite rules this will depend on which version of IIS you are running. If IIS6 then I'd recommend IIRF but if you're running IIS7 or IIS8 then use the built in url rewrite module (installed via Web Platform Installer).
I need to redirect 1000's of URL's of the following format:
http://egauges.com/vdo_mult3.asp?Type=Ammeter&Series=Vision&Units=E
to a new Volusion (unfortunately) ASP.net site with the format
egauges.com/Ammeters-s/22044.htm
Which is actually here for now (http://gnqvn.mzqlg.servertrust.com/Ammeters-s/22044.htm)
The old site will go away once this is working, so redirects must be done on the new site.
Volusion has a 301 redirect "tool", but unfortunately it can't handle anything after the ? in the original URL. Volusion kicked it up the chain in their tech support, but says there isn't a way to do it. I'm sure some sort of script, either server or client side, or maybe even something simpler would work, but despite searching high and low, I can't figure it out.
Thanks!
Dave
Do the redirect directly in the asp site.
Change vdo_mult3.asp so that it redirects anyone who accesses it by using Response.Redirect as follows:
Response.Redirect("http://egauges.com/Ammeters-s/22044.htm")
You can also check the parameters passed to and change the redirect passed on those parameters.
I posted a query for 301-redirect using ASP.NET 3.5 here:
Redirecting default.aspx to root virtual directory
Based on the replies I got there, I realized there might be a bug in ASP.NET's Request.RawUrl method which is unable to return the actual raw url (without /default.aspx) when being used in a sub-directory, i.e. the /default.aspx page is inside a subdirectory.
Can someone please shed some light on this possible bug?
Thanks,
Asif
i found a good explanation here
http://codeasp.net/blogs/vivek_iit/microsoft-net/873/301-redirect-from-default-aspx-to-site-root
Thanks
If you suspect this is a bug, then the place to go is Microsoft Connect, where you can report and discuss the bug directly with Microsoft.
Edit: I was able to reproduce the look per your comments.
I was unable to reproduce the infinite loop, however. I injected code into the Global.asax Application_BeginRequest handler of a web application and got the expected behavior of a single redirect.
There are other, and IMO much better, options for handling global redirect rules. On IIS7, I use the URL Rewrite module to configure rewrite rules in IIS. You can read more about it and download it here: http://www.iis.net/download/urlrewrite. The appeal of a solution such as this is that you can customize and update your rewrite rules without recompiling the application.
Edit: I was able to retrieve the raw URL without the default.aspx (after the redirect) by using instead:
Request.ServerVariables["CACHE_URL"]
It's worth a shot.
Have you looked at the IIS settings for your virtual directory? If there is a default document set to default.aspx then this will explain the infinite loop that you are experiencing. You are telling the website to redirect to the virtual directory without the "default.aspx" and IIS is detecting this on the next request and putting it back in ad infinitum.
Right click your virtual directory, select Properties and then the Documents tab. If default.aspx is in the list then that is what you will get. The Url of the request will be passed to the ASP.NET worker process as /folder/default.aspx rather than /folder/
This is not a bug. If IIS didn't do this, you would get a page not found error.
Sounds to me like you need to investigate URL rewriting: http://msdn.microsoft.com/en-us/library/ms972974.aspx
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
I have website developed in classic ASP. The URL is not SEO friendly at present.
Please suggest how I can make the SEO friendly URL for my website in ASP.
Is there any supporting functions which can help in creating SEO friendly URL in ASP?
URL for product Information page like this :
http://www.yourdomain.com/store/template/template2/Default.asp?mainpage=product_info&P_ID=18047
Thanks for your help.
I have read the documentation and Installed the IIRF properly.Now i have few queries.I tried few sample with redirection and they are wrking.I put the clean URL in address bar and result shows data from the original URL.
My Problems: I am still bit confused abt the rewrite and redirect.I don't expect you to teach and guide me for the same.Please pardon me if i write confusing sometime.Please feel free to guide me if i am wrong in approach for SEO friendly URL's.
My Goal is to create SEO friendly URL's for my shopping cart.what I want when page gets parsed in browser it should show the Parsed links as SEO friendly not the original one.
As in my sample when i type URL in address bar it didn't gets changed to clean URL. When i type the clean URL in address bar it shows the data from original URL.
In my shopping cart there are lot of Hyperlinks to other pages.They are also in Dynamic in nature not the static one.How can i set those static hyperlinks to clean URL using IIRF without making substantial changes in my cart.
regards,
Sunny
Configure IIS to do URL Rewriting. Microsoft has an addon for IIS7 (Vista, Server 2008), but you can install IIRF (open source) in IIS5.1 (XP) and IIS6 (Server 2003).
Let all incoming requests or any path starting with /media/ (or pick your own) go through un-rewritten. Only put static files in there such as CSS/JavaScript/images.
Rewrite all incoming request URLS from, e.g., /foo/bar?abc=xyz to /index.asp/foo/bar?abc=xyz. The rewriting is all internal to IIS so the end-user does not see any URL rewriting.
Within index.asp, you can access the original incoming URL /foo/bar via
<%= Request.ServerVariables("SCRIPT_NAME") %>
<%= Request.ServerVariables("PATH_INFO") %>
<%= Request.ServerVariables("QUERY_STRING") %>
yielding
/index.asp
/foo/bar
abc=xyz
We have used isapi rewrite before and it works very well, very configurable per site etc
http://www.isapirewrite.com/