Bluehost.com Web Hosting $6.95

Apache2 the Trailing Slash problem

This is a discussion on Apache2 the Trailing Slash problem within the Windows Web Servers forums, part of the Web Server and Related Forums category; I am using the mod_rewrite for two purposes. First, to allow dynamic mass virtual hosting via a vhost.map file (...


Go Back   Usenet Forums > Web Server and Related Forums > Windows Web Servers

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-02-2004
William
 
Posts: n/a
Default Apache2 the Trailing Slash problem

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
  #2 (permalink)  
Old 04-06-2004
Joachim Ring
 
Posts: n/a
Default Re: Apache2 the Trailing Slash problem

> 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
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 09:37 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0