Apache and mod_rewrite

Top Page
Attachments:
Message as email
+ (text/plain)
Delete this message
Reply to this message
Author: JD Austin
Date:  
Subject: Apache and mod_rewrite
Joel W. Leibow wrote:

>Alright, I have developed a site that is making extensive use of the rewrite
>module in apache. For example, I have a RewriteMap created that has each
>state listed in it with a corresponding ID relative to the primary key in a
>table in the database. This allows me to search the url for any occurrence
>of /[a-z]+/ and look it up in the RewriteMap. If it matches, the
>corresponding ID is returned and I can query the database with that ID
>
>The problem that I am having is that I also have about 18,000
>sub-directories that I would like to fake. Each directory could also match
>the pattern /[a-z]+/. I don't want to look up the pattern in the RewriteMap
>unless it is definitely a state name. Instead I would like to pass the
>"/sub-directory" that has been requested via the query string for pulling
>info from a database. How do I go about distinguishing each state from each
>possible sub-directory without having to write a regular expression to match
>each state name? I was thinking that RewriteCond could help but am
>uncertain how exactly to use that portion of the rewrite module. Advice?
>
>I realize this is pretty complex, but hopefully my description makes sense.
>Any advice or input would be greatly appreciated.
>
>Joel Leibow
>
>---------------------------------------------------
>PLUG-discuss mailing list -
>To subscribe, unsubscribe, or to change you mail settings:
>http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss
>
>

Why not do it a different way?

I've done this in the past where I wanted to have information in the URL
by using the force type directive
and my favorite scripting language.

In this example, anytime /public/* is in the URL the script runs instead
of actually looking for a directory.

Heres the gist of it:
in httpd.conf:
<Location /public>
ForceType application/x-httpd-php
</Location>

Snippet from 'public' in htdocs (php script):
// -- this is a snipped of php code
// www.site.com/scriptname/parameter1/parameter2/parameter3/etc
      $url_array=explode("/",$REQUEST_URI); 
      $loginid=$url_array[2];
      $loginid=ereg_replace('.html','',$loginid);
      $loginid=ereg_replace('-','',$loginid);


      $year=intval($url_array[3]);
      $month=intval($url_array[4]);
      $day=intval($url_array[5]);


if ($loginid==''){
//if $loginid isnt specified a list of calendars is displayed
             $title="$prodname Public Calendars.  Select a calendar to 
view.";
}
else {
             $title="$prodname ".urldecode($loginid)." Public Calendar";
}
print "<TITLE>$title</TITLE>";       
if( $loginid=='' ){$page='pubList';}else{$page='pMonthly';}     
 //Co-Branding info


if ($refresh){
      print"<META HTTP-EQUIV=\"REFRESH\" 
CONTENT=\"0;URL=/public/$loginid/$year/$month/$day/$visitorhash\"></BODY></HTML>";
}
    else{
// hides it all nicely in a frameset   
    print '<frameset rows="*,0" frameborder="0" border=0 
framespacing="0">\n';
    print "<HTML><HEAD><TITLE>$prodname $dateGren</TITLE></HEAD>\n";


    print "<FRAME SRC = 
\"/$page.phtml?loginid=$loginid&year=$year&month=$month&day=$day&visitorhash=$visitorhash\" 
marginheight=0 marginwidth=9 NAME=CAL>\n";
    print "<NOFRAMES>You must use a browser that can display frames to 
see this page. </NOFRAMES>\n";
    print "</FRAMESET>\n";
         print "<CENTER><a href=\"javascript:history.go(-1)\">Return to 
previous page</A></CENTER><BR>";
}


In the above case I masked the actual page that was being displayed but
I could have generated the page directly inside the 'public' page had I
thought of it at the time.

JD