Solved

asp.net RewritePath in classic asp?

Posted on 2004-09-16
10
1,022 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
Industry Leaders: 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

Suggested Solutions

Title # Comments Views Activity
RegEx Help - open to other simple suggestions 8 63
Select case on click 3 26
Designing forms 3 41
VB script help 23 30
I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
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 informatio…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

740 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