Solved

asp.net RewritePath in classic asp?

Posted on 2004-09-16
10
1,026 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

690 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