mod_rewrite
Brad Bartram
bradbartram at ccsisp.com
Tue Feb 10 16:40:51 EST 2004
For anyone curious, I did solve my problem. Here's the answer, in case anyone
finds themsleves in a similar situation.
First, over at www.modrewrite.com there are some great forums and resources
for all things mod_rewrite.
So without further ado, here goes...
Since I was kind of flying blind having to work remotely on a server I had
very limited access to, I started out by setting up my own environment to
test off of. I created a very stripped down configuration file, which
allowed me to maintain a grasp of everything that was going on.
I created a development area in my home directory so I could access it easily.
Within this public_html development area I created two files:
app.ext - which was just a text file with a message telling me it didn't work
app_results.php - which consisted of the following -
<HTML>
<HEAD>
<TITLE>IT WORKS!!!!!!!!</TITLE>
</HEAD>
<BODY><B>You got it to work!</B><BR><BR>
<?PHP
print_r($_REQUEST);
?>
</BODY>
</HTML>
This allowed me to see that it worked and also view the variables the script
was receiving.
Next I went to my http.conf file and added the following:
RewriteEngine on
RewriteLog /home/brad/rewrite_log
RewriteLogLevel 9
This turned on my Rewrite engine, created a dedicated log file, and finally
set the logging to the highest value so I could debug all of my rules.
Next, to make things easy, I created a <Directory> directive in httpd.conf
which contained my rules and other parameters. A lot of people will use
.htaccess for something like this. I tend not to as having .htaccess enabled
will cause a performance hit on a busy server.
So in my <Directory> directive I put the following:
<Directory "/home/brad/public_html">
Options Indexes +FollowSymLinks
AllowOverride All
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/~brad/([a-z0-9]*.ext)$
RewriteRule ^(.*) /~brad/app_result.php?variable=$1&%{QUERY_STRING} [R]
Order allow,deny
Allow from all
</Directory>
Most of this is pretty standard apache fare. You'll notice I turned on the
rewrite engine in my directory. This allows for this instance of mod_rewrite
by itself.
The rewrite condition checks the incoming URI to see if it contains anything
before the target extension of ext. If so, it goes to the rewrite rule,
which takes the request, and puts the entire final string into the variable
'variable'. It then takes the query string, which is everything after the ?
in the original URI and appends it onto the new URI. The final [R] forceably
rewrites the url.
And that is how I solved my problem.
Thanks to those who offered solutions, it was appreciated. To those who saw
my post and said, "what?!?", hopefully this writeup can provide some
assistance to you if you ever come upon a similar situation.
brad
More information about the nflug
mailing list