You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Ken Gillett <ke...@ukgb.net> on 2003/06/05 12:00:28 UTC

[users@httpd] RedirectMatch = HideMatch

I hate answering my own questions, but I have found that the reason 
matched files are excluded from the listing is because the target is 
not valid. The BIG difference between the earlier v1 and current Apache 
2.0.40 that I'm using is that RedirectMatch no longer accepts relative 
URLs. IOW:

	RedirectMatch "(.*)" ../$1

used to redirect to a file of the same name in the directory above. BUT 
now this generates an error when listing the directory and the file is 
excluded from the listing. If I use an absolute URL it works, but 
that's no good here as the match is needed at different levels. This is 
pretty important for this website.

Has anyone else noticed that RedirectMatch now HAS to have absolute 
URLs? Is this intended, is it a bug, is there any way around it?



Ken  G i l l e t t

_/_/_/_/_/_/_/_/_/


---------------------------------------------------------------------
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] RedirectMatch = HideMatch

Posted by Ken Gillett <ke...@ukgb.net>.
Some things are impossible, others are much easier:-)

For anyone who's interested the following will redirect to a file of 
the same basic name (trimming ~ from the beginning and space from the 
end) in the parent directory:

	RedirectMatch "^(.*)\/([^\/]*\/)~(.*)$" $1/$3

Some slight modification would be required if a different naming 
protocol was used.


On Thursday, June 5, 2003, at 02:55  pm, Joshua Slive wrote:

> On Thu, 5 Jun 2003, Ken Gillett wrote:
>
>> I hate answering my own questions, but I have found that the reason
>> matched files are excluded from the listing is because the target is
>> not valid. The BIG difference between the earlier v1 and current 
>> Apache
>> 2.0.40 that I'm using is that RedirectMatch no longer accepts relative
>> URLs. IOW:
>>
>> 	RedirectMatch "(.*)" ../$1
>
> I'm very surprised that that ever worked.  It may be a case of apache
> sending garbarge to the browser, but the browser being very lenient 
> about
> it.

> What you want could perhaps be arranged by using an appropriate regex
> to construct an absolute URL, but it is difficult to tell exactly
> what you are trying to do.  The configuration you quote above makes no
> sense to me.




Ken  G i l l e t t

_/_/_/_/_/_/_/_/_/


---------------------------------------------------------------------
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] RedirectMatch = HideMatch

Posted by Ken Gillett <ke...@ukgb.net>.
Already figured out what I needed, but thanks anyway.

I take your point about a redirect being different from an href. It's 
the change in Apache's behaviour from v1 to v2 that caught me out. 
Still, all's well that ends well:-)


On Thursday, June 5, 2003, at 06:53  pm, Joshua Slive wrote:

> On Thu, 5 Jun 2003, Joshua Slive wrote:
>> RedirectMatch ^/(.*)/[^/]*/~([^/])$ http://yoursite.example.com/$1/$2
>
> Of course, I always screw up complex regexes.  Try:
> RedirectMatch ^/(.*)/[^/]*/~([^/]*)$ http://yoursite.example.com/$1/$2



Ken  G i l l e t t

_/_/_/_/_/_/_/_/_/


---------------------------------------------------------------------
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] RedirectMatch = HideMatch

Posted by Joshua Slive <jo...@slive.ca>.
On Thu, 5 Jun 2003, Joshua Slive wrote:
> RedirectMatch ^/(.*)/[^/]*/~([^/])$ http://yoursite.example.com/$1/$2

Of course, I always screw up complex regexes.  Try:
RedirectMatch ^/(.*)/[^/]*/~([^/]*)$ http://yoursite.example.com/$1/$2


---------------------------------------------------------------------
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] RedirectMatch = HideMatch

Posted by Joshua Slive <jo...@slive.ca>.

On Thu, 5 Jun 2003, Ken Gillett wrote:
> Well I can't really see that - computers never make sense out of
> garbage:-)

I know you're joking, but what I meant is that Apache did allow users to
send non-RFC compliant redirects in previous version.  Luckily for these
users, the browser would often make some assumptions about what was
intended and perform the redirect anyway.

> The actual line was:
>
> 	RedirectMatch ".*~(.*[^ ]) ?$" ../$1

> > The docs for Redirect/RedirectMatch are quite clear that only an
> > absolute URL is acceptable:
> > http://httpd.apache.org/docs-2.0/mod/mod_alias.html#redirect
>
> Actually, I don't think that is true

The second parameter, according to the "Syntax" is "URL".  If you consult
http://httpd.apache.org/docs-2.0/mod/directive-dict.html#Syntax
you'll see that URL means an absolute URL starting with a scheme and
hostname.

> Seems to have made sense with Apache v1. I'll have a look at some fancy
> regex'ing, but any more assistance with this problem would be much
> appreciated.

It doesn't make sense because the "Location:" HTTP response header
generated by Apache must contain an absolute URL according to the HTTP
specs (RFC 2616 sec 14.30).  You seem to think that a redirect is like an
<a href>, but it is not.  It does not have the same url resolution rules.

Now, I suppose that Apache could impliment those rules for you to send
back to browser, but I think that the results wouldn't be very pleasing in
general, because it would be very difficult to recreate the exact behavior
of the browser in response to that link.

But all is not lost.  Something approaching what you want is

RedirectMatch ^/(.*)/[^/]*/~([^/])$ http://yoursite.example.com/$1/$2

What this does is simply remove the last directory for any filename
starting in ~.  I haven't dealt with the space issue, but you can probably
work that in (although the existence of a bare space seems very unlikely).

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] RedirectMatch = HideMatch

Posted by Ken Gillett <ke...@ukgb.net>.
On Thursday, June 5, 2003, at 02:55  pm, Joshua Slive wrote:

> On Thu, 5 Jun 2003, Ken Gillett wrote:
>
>> I hate answering my own questions, but I have found that the reason
>> matched files are excluded from the listing is because the target is
>> not valid. The BIG difference between the earlier v1 and current 
>> Apache
>> 2.0.40 that I'm using is that RedirectMatch no longer accepts relative
>> URLs. IOW:
>>
>> 	RedirectMatch "(.*)" ../$1
>
> I'm very surprised that that ever worked.  It may be a case of apache
> sending garbarge to the browser, but the browser being very lenient 
> about
> it.

Well I can't really see that - computers never make sense out of 
garbage:-)

The actual line was:

	RedirectMatch ".*~(.*[^ ]) ?$" ../$1

This would match any file that started with a ~ and 'may' have ended in 
a space. The file served would then be a file in the parent directory 
of the same name as the root of the clicked file, i.e. with no leading 
~ or trailing space.

This worked perfectly and was a simulation of a Mac alias file, which 
is exactly what the ~ prefixed file is, created when the server volume 
is mounted on a Mac. Limited of course to only redirecting to the 
parent directory, but that is exactly what is required in this case and 
so entirely sufficient.

> The docs for Redirect/RedirectMatch are quite clear that only an
> absolute URL is acceptable:
> http://httpd.apache.org/docs-2.0/mod/mod_alias.html#redirect

Actually, I don't think that is true - it is the first parameter (i.e. 
what you are trying to match) that is stated as having to be absolute 
and that is not mentioned for RedirectMatch. Hardly surprising since 
that parameter has to be a regex pattern.

As for the second parameter, any absolute requirement is not mentioned 
and it used to work as a relative path (as in any actual html code), 
but now it must be absolute and that's a real PIA.

> What you want could perhaps be arranged by using an appropriate regex
> to construct an absolute URL, but it is difficult to tell exactly
> what you are trying to do.  The configuration you quote above makes no
> sense to me.

Seems to have made sense with Apache v1. I'll have a look at some fancy 
regex'ing, but any more assistance with this problem would be much 
appreciated.




Ken  G i l l e t t

_/_/_/_/_/_/_/_/_/


---------------------------------------------------------------------
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] RedirectMatch = HideMatch

Posted by Joshua Slive <jo...@slive.ca>.
On Thu, 5 Jun 2003, Ken Gillett wrote:

> I hate answering my own questions, but I have found that the reason
> matched files are excluded from the listing is because the target is
> not valid. The BIG difference between the earlier v1 and current Apache
> 2.0.40 that I'm using is that RedirectMatch no longer accepts relative
> URLs. IOW:
>
> 	RedirectMatch "(.*)" ../$1

I'm very surprised that that ever worked.  It may be a case of apache
sending garbarge to the browser, but the browser being very lenient about
it.

The docs for Redirect/RedirectMatch are quite clear that only an
absolute URL is acceptable:
http://httpd.apache.org/docs-2.0/mod/mod_alias.html#redirect

What you want could perhaps be arranged by using an appropriate regex
to construct an absolute URL, but it is difficult to tell exactly
what you are trying to do.  The configuration you quote above makes no
sense to me.

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