You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Ari Davidow <ar...@ivritype.com> on 2004/01/06 19:34:34 UTC

[users@httpd] stripping trailing slash

I am running an application (written in php, if that matters) such that 
whatever string someone types after the server name should be passed to the 
application as an argument, e.g., for

http://www.foo.com/dothis

"dothis" is passed to the application.

Unfortunately, knowledgeable people keep adding trailing slashes, which 
seems to break things. I haven't found a working way to remove the trailing 
slash (if extant) prior to passing the string to my application.

I am using mod_rewrite, and first tried:

         ReWriteRule ^/notfound.html - [L]
         ReWriteRule ^/([-a-zA-Z0-9_]*)?/+$ /myscript/$1 
[T=application/x-httpd-php]

which simply doesn't seem to catch anything (vs.

         ReWriteRule ^/([-a-zA-Z0-9_]*)?$ /myscript/$1 
[T=application/x-httpd-php]

which works for everything but strings with trailing slashes.

What obvious thing am I missing? Surely this should be trivial.

ari


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


[users@httpd] Vitrual Host Bandwidth Throttle

Posted by Jason D <ja...@codepanzyz.com>.
Server version: Apache/2.0.48

Hello everyone,
        I am hoping that someone will be able to help with this seening as I
have been looking for a sometime now for an answer. I would like to limit
bandwidth on a per virtual host per month basis.
e.g.
vhost #1 allowed 1GB data transfer a month
vhost #2 allowed 5GB data transfer a month
vhost #3 allowed 2.6GB data transfer a month
I can not seem to find anyway to do this with apache 2.0 I have looked at
apache 1.x and seen a couple of modules that look like they were designed
with this in mind e.g. mod_throttle, mod_bandwidth and mod_bwshare, found
via http://modules.apache.org/search,  but I can not find an equal counter
part for Apache 2.0. I have looked in every crack of the internet (Yep,
serched the whole thing) and have not been able to find a way to do this.
      First off does anyone know how this can be done or know where I can
find the resourse to learn how to do this?
Would rolling back to the current 1.x version be a viable option and has
anyone limited per vhost per month with 1.x? F.Y.I. I have never used Apache
1 and also have php and sql support.
    I am willing to move to another web server as well if anyone has a
sugsestion of one that can do what I'm looking for. E.G. roxen, thttpd, not
too sure how I feel about kernel based web servers, and Zeus is a little out
of my price range ;-P. Well thanks for the help.
                                                  Jason








---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] stripping trailing slash

Posted by Ari Davidow <ar...@ivritype.com>.
At 02:00 PM 1/7/2004, you wrote:
>On Wed, 7 Jan 2004, Ari Davidow wrote:
> > > > >ReWriteRule ^/([-a-zA-Z0-9_]*)/*$ /myscript/$1 
> [T=application/x-httpd-php]
>
> > Going through the RewriteLog we determined that the Rewrite =was= working
> > as expected -- the problem actually lay inside the PHP script, where the
> > variable REQUEST_URI was being parsed to get the string. That variable was
> > not affected by the rewrite (should it have been? if so, any ideas why it
> > wasn't changed?). Is this the wrong environment variable to use? Is anyone
> > familiar with PHP who would know what should properly be used instead?
>
>REQUEST_URI shows the actual request from the client.  You can either deal
>with that in your php script, or you can tell the client to correct their
>request using an external redirect.  This may be a good idea for other
>reasons --- it's wise to only have one URL that points to any particular
>resource.  A technique to do that would be something like
>
>RewriteRule ^(/[^/]+)/ $1 [R]
>
>ReWriteRule ^/([-a-zA-Z0-9_]*)$ /myscript/$1 [T=application/x-httpd-php]


Slick. Thank you.

ari



---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] stripping trailing slash

Posted by Joshua Slive <jo...@slive.ca>.
On Wed, 7 Jan 2004, Ari Davidow wrote:
> > > >ReWriteRule ^/([-a-zA-Z0-9_]*)/*$ /myscript/$1 [T=application/x-httpd-php]

> Going through the RewriteLog we determined that the Rewrite =was= working
> as expected -- the problem actually lay inside the PHP script, where the
> variable REQUEST_URI was being parsed to get the string. That variable was
> not affected by the rewrite (should it have been? if so, any ideas why it
> wasn't changed?). Is this the wrong environment variable to use? Is anyone
> familiar with PHP who would know what should properly be used instead?

REQUEST_URI shows the actual request from the client.  You can either deal
with that in your php script, or you can tell the client to correct their
request using an external redirect.  This may be a good idea for other
reasons --- it's wise to only have one URL that points to any particular
resource.  A technique to do that would be something like

RewriteRule ^(/[^/]+)/ $1 [R]

ReWriteRule ^/([-a-zA-Z0-9_]*)$ /myscript/$1 [T=application/x-httpd-php]

Joshua.

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] stripping trailing slash

Posted by Ari Davidow <ar...@ivritype.com>.
At 04:32 PM 1/6/2004, you wrote:
>On Tue, 6 Jan 2004, Ari Davidow wrote:
> > >ReWriteRule ^/([-a-zA-Z0-9_]*)/*$ /myscript/$1 [T=application/x-httpd-php]
>
> > No, this doesn't work either, although you're right - it's cleaner. I'm
> > wondering if there is something that apache does when it sees the trailing
> > slash to assume that a directory is intended that is different from the
> > usual parsing? Or something that I need to do to indicate that the slash
> > should be treated as a literal character, not as the usual symbol for
> > "directory"?
>
>No.
>
>The next step is to use the RewriteLog to see exactly what mod_rewrite is
>doing.  Turn up the RewriteLogLevel to 9 and post here if you don't
>understand the contents.


Going through the RewriteLog we determined that the Rewrite =was= working 
as expected -- the problem actually lay inside the PHP script, where the 
variable REQUEST_URI was being parsed to get the string. That variable was 
not affected by the rewrite (should it have been? if so, any ideas why it 
wasn't changed?). Is this the wrong environment variable to use? Is anyone 
familiar with PHP who would know what should properly be used instead?

ari


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] stripping trailing slash

Posted by Joshua Slive <jo...@slive.ca>.
On Tue, 6 Jan 2004, Ari Davidow wrote:
> >ReWriteRule ^/([-a-zA-Z0-9_]*)/*$ /myscript/$1 [T=application/x-httpd-php]

> No, this doesn't work either, although you're right - it's cleaner. I'm
> wondering if there is something that apache does when it sees the trailing
> slash to assume that a directory is intended that is different from the
> usual parsing? Or something that I need to do to indicate that the slash
> should be treated as a literal character, not as the usual symbol for
> "directory"?

No.

The next step is to use the RewriteLog to see exactly what mod_rewrite is
doing.  Turn up the RewriteLogLevel to 9 and post here if you don't
understand the contents.

Joshua.

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] stripping trailing slash

Posted by Ari Davidow <ar...@ivritype.com>.
At 04:05 PM 1/6/2004, Joshua Slive wrote:
>On Tue, 6 Jan 2004, Ari Davidow wrote:
> > I am using mod_rewrite, and first tried:
> >
> >          ReWriteRule ^/notfound.html - [L]
> >          ReWriteRule ^/([-a-zA-Z0-9_]*)?/+$ /myscript/$1
> > [T=application/x-httpd-php]
> >
> > which simply doesn't seem to catch anything (vs.
>
>That doesn't catch requests with trailing slashes?  It looks like it
>should.  But you probably want something more like
>ReWriteRule ^/([-a-zA-Z0-9_]*)/*$ /myscript/$1 [T=application/x-httpd-php]
>to handle both cases.
>
>The question mark is unnecessary since "*" matches zero or more of the
>previous character.


No, this doesn't work either, although you're right - it's cleaner. I'm 
wondering if there is something that apache does when it sees the trailing 
slash to assume that a directory is intended that is different from the 
usual parsing? Or something that I need to do to indicate that the slash 
should be treated as a literal character, not as the usual symbol for 
"directory"?

ari



---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] stripping trailing slash

Posted by Joshua Slive <jo...@slive.ca>.
On Tue, 6 Jan 2004, Ari Davidow wrote:
> I am using mod_rewrite, and first tried:
>
>          ReWriteRule ^/notfound.html - [L]
>          ReWriteRule ^/([-a-zA-Z0-9_]*)?/+$ /myscript/$1
> [T=application/x-httpd-php]
>
> which simply doesn't seem to catch anything (vs.

That doesn't catch requests with trailing slashes?  It looks like it
should.  But you probably want something more like
ReWriteRule ^/([-a-zA-Z0-9_]*)/*$ /myscript/$1 [T=application/x-httpd-php]
to handle both cases.

The question mark is unnecessary since "*" matches zero or more of the
previous character.

Joshua.

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org