You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Craig Whitmore <no...@spam.co.nz> on 2003/05/05 22:47:10 UTC

[users@httpd] Rewriting the Trailing Slash

Hi there

I am trying to "fix the trailing slash problem" using rewrite, but the
examples given use RewriteBase which you can't use using vhosts.
Can anyone help? See my existing config below.

ie http://www.website1.com/blah  -> http://www.website1.com/blah/

If I use the

RewriteCond    %{REQUEST_FILENAME}  -d
RewriteRule    ^/(.*)$           $1/  [R]

then http://www.website1.com/blah ->
http://www.website1.com/home/username/blah/

As it can't remove the /home/username/  as you can't use RewriteBase at all.

Thanks
Craig Whitmore


The Directories are set as /home/username/website1.com
/home/username/website2.com etc
with vhost.map =

domain1.com /home/user1/www.website2.com
domain2.com /home/user1/www.website3.com
domain3.com /home/user2/www.website4.com

etc


<VirtualHost *>
        RewriteEngine on
         DirectoryIndex index.html index.htm default.htm default.html

        RewriteMap    lowercase    int:tolower
        RewriteMap    vhost        txt:vhost.map
        RewriteCond   %{REQUEST_FILENAME}  !^/cgi-bin/branding.pl
        RewriteCond   %{REQUEST_FILENAME}  !^/error
        RewriteCond   %{REQUEST_URI}  !^/icons/
        RewriteCond   %{HTTP_HOST}  !^$
        RewriteCond   ${lowercase:%{HTTP_HOST}|NONE}  ^(.+)$
        RewriteCond   ${vhost:%1}  ^(/.*)$
        RewriteRule   ^/(.*)$   %1/$1  [E=VHOST:${lowercase:%{HTTP_HOST}}]

        ScriptAlias /cgi-bin/ /hosting/cgi-bin/

      #rewriter to add in "banners etc"
      Action add-header /cgi-bin/branding.pl
      AddHandler add-header .html .htm .shtml

    </VirtualHost>


---------------------------------------------------------------------
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] Rewriting the Trailing Slash

Posted by Craig Whitmore <no...@spam.co.nz>.
It doesn't seem to work.. :-( See log..

x.x.x.x - - [06/May/2003:18:23:32 +1200]
[testbox.orcon.co.nz/sid#80f9198][rid#81568f8/initial] (2) init rewrite
engine with requested uri /
x.x.x.x - - [06/May/2003:18:23:32 +1200]
[testbox.orcon.co.nz/sid#80f9198][rid#81568f8/initial] (3) applying pattern
'^/(.*)$' to uri '/'
x.x.x.x - - [06/May/2003:18:23:32 +1200]
[testbox.orcon.co.nz/sid#80f9198][rid#81568f8/initial] (4) RewriteCond:
input='/' pattern='!^/cgi-bin/orconbranding.pl' => matched
x.x.x.x - - [06/May/2003:18:23:32 +1200]
[testbox.orcon.co.nz/sid#80f9198][rid#81568f8/initial] (4) RewriteCond:
input='/' pattern='!^/error' => matched
x.x.x.x - - [06/May/2003:18:23:32 +1200]
[testbox.orcon.co.nz/sid#80f9198][rid#81568f8/initial] (4) RewriteCond:
input='/' pattern='!^/icons/' => matched
x.x.x.x - - [06/May/2003:18:23:32 +1200]
[testbox.orcon.co.nz/sid#80f9198][rid#81568f8/initial] (4) RewriteCond:
input='test1.orcon.net.nz' pattern='!^$' => matched
x.x.x.x - - [06/May/2003:18:23:32 +1200]
[testbox.orcon.co.nz/sid#80f9198][rid#81568f8/initial] (5) map lookup OK:
map=lowercase key=test1.orcon.net.nz -> val=test1.orcon.net.nz
x.x.x.x - - [06/May/2003:18:23:32 +1200]
[testbox.orcon.co.nz/sid#80f9198][rid#81568f8/initial] (4) RewriteCond:
input='test1.orcon.net.nz' pattern='^(.+)$' => matched
x.x.x.x - - [06/May/2003:18:23:32 +1200]
[testbox.orcon.co.nz/sid#80f9198][rid#81568f8/initial] (5) cache lookup OK:
map=vhost[txt] key=test1.orcon.net.nz -> val=/home/test1
x.x.x.x - - [06/May/2003:18:23:32 +1200]
[testbox.orcon.co.nz/sid#80f9198][rid#81568f8/initial] (4) RewriteCond:
input='/home/test1' pattern='^(/.*)$' => matched
x.x.x.x - - [06/May/2003:18:23:32 +1200]
[testbox.orcon.co.nz/sid#80f9198][rid#81568f8/initial] (2) rewrite / ->
/home/test1/
x.x.x.x - - [06/May/2003:18:23:32 +1200]
[testbox.orcon.co.nz/sid#80f9198][rid#81568f8/initial] (5) map lookup OK:
map=lowercase key=test1.orcon.net.nz -> val=test1.orcon.net.nz
x.x.x.x - - [06/May/2003:18:23:32 +1200]
[testbox.orcon.co.nz/sid#80f9198][rid#81568f8/initial] (5) setting env
variable 'VHOST' to 'test1.orcon.net.nz'
x.x.x.x - - [06/May/2003:18:23:32 +1200]
[testbox.orcon.co.nz/sid#80f9198][rid#81568f8/initial] (3) applying pattern
'^(/.+)$' to uri '/home/test1/'
x.x.x.x - - [06/May/2003:18:23:32 +1200]
[testbox.orcon.co.nz/sid#80f9198][rid#81568f8/initial] (4) RewriteCond:
input='/home/test1/' pattern='-d' => matched
x.x.x.x - - [06/May/2003:18:23:32 +1200]
[testbox.orcon.co.nz/sid#80f9198][rid#81568f8/initial] (2) rewrite
/home/test1/ -> /home/test1//
x.x.x.x - - [06/May/2003:18:23:32 +1200]
[testbox.orcon.co.nz/sid#80f9198][rid#81568f8/initial] (2) explicitly
forcing redirect with http://testbox.orcon.co.nz/home/test1//
x.x.x.x - - [06/May/2003:18:23:32 +1200]
[testbox.orcon.co.nz/sid#80f9198][rid#81568f8/initial] (1) escaping
http://testbox.orcon.co.nz/home/test1// for redirect
x.x.x.x - - [06/May/2003:18:23:32 +1200]
[testbox.orcon.co.nz/sid#80f9198][rid#81568f8/initial] (1) redirect to
http://testbox.orcon.co.nz/home/test1// [REDIRECT/302]

----- Original Message -----
From: "Garth Winter Webb" <ga...@perijove.com>
To: <us...@httpd.apache.org>
Sent: Tuesday, May 06, 2003 10:01 AM
Subject: Re: [users@httpd] Rewriting the Trailing Slash


> Actually you do want the slash explicitly in there so '/' isn't
> rewritten to '//':
>
> RewriteRule    ^(/.+)$           $1/  [R]
>
> On Mon, 2003-05-05 at 14:55, Garth Winter Webb wrote:
> > You could change your rewrite rule to include the slash:
> >
> > RewriteRule    ^(/.*)$           $1/  [R]
> >
> > or really just:
> >
> > RewriteRule    ^(.*)$           $1/  [R]
> >
> > On Mon, 2003-05-05 at 14:40, Craig Whitmore wrote:
> > > Can you suggest what do you to make it work?
> > >
> > > Thanks
> > > Craig
> > >
> > > ----- Original Message -----
> > > From: "Garth Winter Webb" <ga...@perijove.com>
> > > To: <us...@httpd.apache.org>
> > > Sent: Tuesday, May 06, 2003 9:11 AM
> > > Subject: Re: [users@httpd] Rewriting the Trailing Slash
> > >
> > >
> > > > On Mon, 2003-05-05 at 13:47, Craig Whitmore wrote:
> > > > <snip>
> > > > > If I use the
> > > > >
> > > > > RewriteCond    %{REQUEST_FILENAME}  -d
> > > > > RewriteRule    ^/(.*)$           $1/  [R]
> > > > >
> > > > > then http://www.website1.com/blah ->
> > > > > http://www.website1.com/home/username/blah/
> > > > >
> > > > > As it can't remove the /home/username/  as you can't use
RewriteBase at
> > > all.
> > > >
> > > > Are you sure this isn't happening because you rewrite to a relative
> > > > path?  Your rewrite rule matches the initial '/' but doesn't capture
it
> > > > in the parenthesis.  Thus you rewrite the absolute path '/blah' to
the
> > > > relative path 'blah/'.
> > > >
> > > > --
> > > > Garth Winter Webb <ga...@perijove.com>
> > > >
> > >
> ---------------------------------------------------------------------
> > > > 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
> > > >
> > > >
> > >
> > >
> > > ---------------------------------------------------------------------
> > > 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
> --
> Garth Winter Webb <ga...@perijove.com>
>
> ---------------------------------------------------------------------
> 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
>
>


---------------------------------------------------------------------
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] Rewriting the Trailing Slash

Posted by Garth Winter Webb <ga...@perijove.com>.
Actually you do want the slash explicitly in there so '/' isn't
rewritten to '//':

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

On Mon, 2003-05-05 at 14:55, Garth Winter Webb wrote:
> You could change your rewrite rule to include the slash:
> 
> RewriteRule    ^(/.*)$           $1/  [R]
> 
> or really just:
> 
> RewriteRule    ^(.*)$           $1/  [R]
> 
> On Mon, 2003-05-05 at 14:40, Craig Whitmore wrote:
> > Can you suggest what do you to make it work?
> > 
> > Thanks
> > Craig
> > 
> > ----- Original Message -----
> > From: "Garth Winter Webb" <ga...@perijove.com>
> > To: <us...@httpd.apache.org>
> > Sent: Tuesday, May 06, 2003 9:11 AM
> > Subject: Re: [users@httpd] Rewriting the Trailing Slash
> > 
> > 
> > > On Mon, 2003-05-05 at 13:47, Craig Whitmore wrote:
> > > <snip>
> > > > If I use the
> > > >
> > > > RewriteCond    %{REQUEST_FILENAME}  -d
> > > > RewriteRule    ^/(.*)$           $1/  [R]
> > > >
> > > > then http://www.website1.com/blah ->
> > > > http://www.website1.com/home/username/blah/
> > > >
> > > > As it can't remove the /home/username/  as you can't use RewriteBase at
> > all.
> > >
> > > Are you sure this isn't happening because you rewrite to a relative
> > > path?  Your rewrite rule matches the initial '/' but doesn't capture it
> > > in the parenthesis.  Thus you rewrite the absolute path '/blah' to the
> > > relative path 'blah/'.
> > >
> > > --
> > > Garth Winter Webb <ga...@perijove.com>
> > >
> > > ---------------------------------------------------------------------
> > > 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
> > >
> > >
> > 
> > 
> > ---------------------------------------------------------------------
> > 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
-- 
Garth Winter Webb <ga...@perijove.com>

---------------------------------------------------------------------
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] Rewriting the Trailing Slash

Posted by Garth Winter Webb <ga...@perijove.com>.
You could change your rewrite rule to include the slash:

RewriteRule    ^(/.*)$           $1/  [R]

or really just:

RewriteRule    ^(.*)$           $1/  [R]

On Mon, 2003-05-05 at 14:40, Craig Whitmore wrote:
> Can you suggest what do you to make it work?
> 
> Thanks
> Craig
> 
> ----- Original Message -----
> From: "Garth Winter Webb" <ga...@perijove.com>
> To: <us...@httpd.apache.org>
> Sent: Tuesday, May 06, 2003 9:11 AM
> Subject: Re: [users@httpd] Rewriting the Trailing Slash
> 
> 
> > On Mon, 2003-05-05 at 13:47, Craig Whitmore wrote:
> > <snip>
> > > If I use the
> > >
> > > RewriteCond    %{REQUEST_FILENAME}  -d
> > > RewriteRule    ^/(.*)$           $1/  [R]
> > >
> > > then http://www.website1.com/blah ->
> > > http://www.website1.com/home/username/blah/
> > >
> > > As it can't remove the /home/username/  as you can't use RewriteBase at
> all.
> >
> > Are you sure this isn't happening because you rewrite to a relative
> > path?  Your rewrite rule matches the initial '/' but doesn't capture it
> > in the parenthesis.  Thus you rewrite the absolute path '/blah' to the
> > relative path 'blah/'.
> >
> > --
> > Garth Winter Webb <ga...@perijove.com>
> >
> > ---------------------------------------------------------------------
> > 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
> >
> >
> 
> 
> ---------------------------------------------------------------------
> 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
-- 
Garth Winter Webb <ga...@perijove.com>

---------------------------------------------------------------------
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] Rewriting the Trailing Slash

Posted by Craig Whitmore <no...@spam.co.nz>.
Can you suggest what do you to make it work?

Thanks
Craig

----- Original Message -----
From: "Garth Winter Webb" <ga...@perijove.com>
To: <us...@httpd.apache.org>
Sent: Tuesday, May 06, 2003 9:11 AM
Subject: Re: [users@httpd] Rewriting the Trailing Slash


> On Mon, 2003-05-05 at 13:47, Craig Whitmore wrote:
> <snip>
> > If I use the
> >
> > RewriteCond    %{REQUEST_FILENAME}  -d
> > RewriteRule    ^/(.*)$           $1/  [R]
> >
> > then http://www.website1.com/blah ->
> > http://www.website1.com/home/username/blah/
> >
> > As it can't remove the /home/username/  as you can't use RewriteBase at
all.
>
> Are you sure this isn't happening because you rewrite to a relative
> path?  Your rewrite rule matches the initial '/' but doesn't capture it
> in the parenthesis.  Thus you rewrite the absolute path '/blah' to the
> relative path 'blah/'.
>
> --
> Garth Winter Webb <ga...@perijove.com>
>
> ---------------------------------------------------------------------
> 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
>
>


---------------------------------------------------------------------
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] Rewriting the Trailing Slash

Posted by Garth Winter Webb <ga...@perijove.com>.
On Mon, 2003-05-05 at 13:47, Craig Whitmore wrote:
<snip>
> If I use the
> 
> RewriteCond    %{REQUEST_FILENAME}  -d
> RewriteRule    ^/(.*)$           $1/  [R]
> 
> then http://www.website1.com/blah ->
> http://www.website1.com/home/username/blah/
> 
> As it can't remove the /home/username/  as you can't use RewriteBase at all.

Are you sure this isn't happening because you rewrite to a relative
path?  Your rewrite rule matches the initial '/' but doesn't capture it
in the parenthesis.  Thus you rewrite the absolute path '/blah' to the
relative path 'blah/'.  

-- 
Garth Winter Webb <ga...@perijove.com>

---------------------------------------------------------------------
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