Solved

asp.net RewritePath in classic asp?

Posted on 2004-09-16
10
1,000 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
 

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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

707 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now