Web Servers on Windows - Apache2 the Trailing Slash problem

This is Interesting: Free IT Magazines  
Home > Archive > Web Servers on Windows > April 2004 > Apache2 the Trailing Slash problem





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Apache2 the Trailing Slash problem
William

2004-04-02, 2:38 pm

I am using the mod_rewrite for two purposes. First, to allow dynamic
mass virtual hosting via a vhost.map file (see bottom of
http://httpd.apache.org/docs-2.0/vhosts/mass.html). Secondly, I want
any requests for directory names made entirely of numbers to be
redirected to a specific php script file in my root dir.

I have it working with the code below in my httpd.conf
-----------------------------------------
RewriteEngine on

RewriteMap lowercase int:tolower

# define the map file
RewriteMap vhost txt:/Apache2/conf/vhost.map

# deal with aliases as above
RewriteCond %{REQUEST_URI} !^/icons/
RewriteCond %{REQUEST_URI} !^/cgi-bin/
RewriteCond %{REQUEST_URI} !^/php4/
RewriteCond ${lowercase:%{SERVER_NAME}} ^(.+)$

# this does the file-based remap
RewriteCond ${vhost:%1} ^(/.*)$
RewriteRule ^/(.*)$ %1/$1

RewriteCond %{REQUEST_URI} ^/cgi-bin/
RewriteCond ${lowercase:%{SERVER_NAME}} ^(.+)$
RewriteCond ${vhost:%1} ^(/.*)$
RewriteRule ^/(.*)$ %1/cgi-bin/$1

RewriteCond %{REQUEST_URI} ^/([0-9]*)/
RewriteCond ${lowercase:%{SERVER_NAME}} ^(.+)$
RewriteCond ${vhost:%1} ^(/.*)$
RewriteRule ^/(.*)$ %1/test.php
----------------------------------------

www.mydomain.com/123/ works beautifully - it actually redirects the
request to my script "script.php" in the root and the browser address
bar still tells the user he is at www.mydomain.com/123/

www.mydomain.com/123 however posts a 404 error. I need to add to my
rewrite code in the httpd.conf something that handles such an
exception

I've tried to incorporate the example in the Apache2 URL Rewrite guide
to no avail. (http://httpd.apache.org/docs-2.0/misc/rewriteguide.html)

Any help on the matter would be greatly appreciated!

William
haunwATspcollege.edu
St. Petersburg College
Joachim Ring

2004-04-06, 6:40 pm

> RewriteCond %{REQUEST_URI} ^/([0-9]*)/
> RewriteCond ${lowercase:%{SERVER_NAME}} ^(.+)$
> RewriteCond ${vhost:%1} ^(/.*)$
> RewriteRule ^/(.*)$ %1/test.php
> ----------------------------------------
>
> www.mydomain.com/123/ works beautifully - it actually redirects the
> request to my script "script.php" in the root and the browser address
> bar still tells the user he is at www.mydomain.com/123/
>
> www.mydomain.com/123 however posts a 404 error. I need to add to my
> rewrite code in the httpd.conf something that handles such an
> exception


the reason for the failure is quite obviously the fact that /123 does
not match ^/([0-9]*)/ - the evident approach of ^/([0-9]*) will
probably bite you when somebody has a file /123go.html, though.

try the following:
RewriteCond %{REQUEST_URI} ^/([0-9]*)/ [OR]
RewriteCond %{REQUEST_URI} ^/([0-9]*)$
RewriteCond ${lowercase:%{SERVER_NAME}} ^(.+)$
RewriteCond ${vhost:%1} ^(/.*)$
RewriteRule ^/(.*)$ %1/test.php

joachim
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com