Solved

asp.net RewritePath in classic asp?

Posted on 2004-09-16
10
1,018 Views
Last Modified: 2007-12-19
I have the following asp.net script that works great for what i need. The only problem is that i cant get it to work with normal classic asp files. What i need is something that works just like the asp.net code but for classic asp.

Thanks in advanced for your help. This one has left me clueless for some time now.

asp.net script:
----
<script language="C#" runat="server">

protected void Application_BeginRequest(Object sender, EventArgs e)
{
      HttpContext incoming = HttpContext.Current;
      string oldpath = incoming.Request.Path.ToLower();

      string pageid; // page id requested

      // Regular expressions to grab the page id from the pageX.aspx
      Regex regex = new Regex(@"topic(\d+).aspx",  RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);
      MatchCollection matches = regex.Matches(oldpath);

      if (matches.Count > 0)
      {
            // Extract the page id and send it to Process.aspx
            pageid = matches[0].Groups[1].ToString();
            incoming.RewritePath("forum_posts.asp?TID=" + pageid);
      } else {
            // Display path if it doesn’t containt pageX.aspx
            incoming.RewritePath(oldpath);
      }
}

</script>
0
Comment
Question by:MadDog986
  • 5
  • 5
10 Comments
 
LVL 6

Expert Comment

by:Mike_Metro
ID: 12074025
0
 

Author Comment

by:MadDog986
ID: 12079493
I need to be able to create this would using a DLL or some kind of add-on for IIS.

This has to be done with normal code.
0
 
LVL 6

Expert Comment

by:Mike_Metro
ID: 12083912
Read this article.  It goes into the details a little.  
http://www.webmasterworld.com/forum47/64-2-10.htm

- Change the 404 error page to a script you create. (ex.  Redirect404.asp)
- In the Redirect404.asp page have similar logic to your aspx page.  
  - Read the current request url
  - Set the status to 200
  - Server.execute or response.redirect to the appropriate page based on the url.

It's not nearly as nice as in ASP.NET or other web languages.  Without using ISAPI, this is really the only way to do it.
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

Author Comment

by:MadDog986
ID: 12089674
All that script does is a redirect. I am trying to turn my urls into something more cleaner so search engines can index my site better.

Example:

I want the page to query http://www.site.com/page?ID=1&Page=Test but the URL will show something like http://www.site.com/page/1/test


Keep in mind am i using a shared host. So dlls or add-ons for IIS is out of the question. The best thing i found that works is the asp.net example above but for some reason it will not except regular .asp extensions for the RewriteURL.
0
 
LVL 6

Expert Comment

by:Mike_Metro
ID: 12101795
I'm not sure if this will work.  But give it a try.  The regular expression is only checking for aspx files.  Try changing it to:

     Regex regex = new Regex(@"topic(\d+).asp[x]?",  RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);
0
 

Author Comment

by:MadDog986
ID: 12106609
I still get a asp.net error when trying to run the script:

"This type of page is not served."
0
 

Author Comment

by:MadDog986
ID: 12117596
If this helps, what i am trying to do is hide the old URLs with new ones without having to install some special component or use a IIS url filter.

Basically what i want to do is turn:

http://www.site.com/forum/forum_posts.asp?TID=(number)

into something like

http://www.site.com/forum/forum_posts/(number) or http://www.site.com/forum/1/forum_posts.asp

If anyone knows a way to do this please help me.
0
 
LVL 6

Expert Comment

by:Mike_Metro
ID: 12123183
Many ISPs allow you to create custom 404 error pages.  Check your ISP docs and their control panel if you have one.  That's really going to be the only way to do it without installing a special component.

0
 

Author Comment

by:MadDog986
ID: 12125371
All 404 pages do is allow you to do a redirect. I cant do a redirect because the URL will not stay the same.
0
 
LVL 6

Accepted Solution

by:
Mike_Metro earned 500 total points
ID: 12126940
Instead of using a response.redirect.  Try using Server.execute.  That may work.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question