You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Jon Block <ht...@collegepublisher.com> on 2003/12/08 16:01:33 UTC

[users@httpd] Please help me with this error document directive

Here is an example of an HTTP GET request I'm making on my Apache server...

http://www.bbtp.com/news/2003/02/06/ArtsAndEntertainment/What.I.want.for.my.
birthday.shtml

Okay... "/news" happens to be a virtual directory (alias) but I don't think
that matters for what I'm trying to do. I've got some programming that is
supposed to create the "ArtsAndEntertainment" directory and then plunk the
".shtml" file into place. However, this process could fail or a request
could come into my server for that file before it was created by my code.

I am trying to figure out how to tell Apache "If you get a request like
this, serve out "/bling.cfm" instead. However, I only want to serve out
"/bling.cfm" if the "ArtsAndEntertainment" folder is missing.

I know I need to use the <directorymatch> or <filematch> tag, or some
combination. Keep in mind the name of the "artsandentertainment" folder will
vary so I have to use an expression. Also, I only want to execute the error
catch if the user specifically tried to access a ".shtml" file.

<FilesMatch "X:/news/[0-9]{4}/[0-9]{2}/[0-9]{2}/.+/.+\.shtml$">
	ErrorDocument 404 /bling.cfm
</FilesMatch>

However, this doesn't work... i get a 404 error when i try my request.
Please help!

Thanks,
Jon


---------------------------------------------------------------------
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] Please help me with this error document directive

Posted by Robert Andersson <ro...@profundis.nu>.
Jon Block wrote:
>  RewriteEngine On #turns on mod_rewrite

Not sure if you are really using that, but you cannot have comments like
that; they must be on their own line.

>  RewriteCond %{REQUEST_FILENAME} !-s

Hmm...  I suggested the -f flag, how come you use -s? For performance
reasons, I think it is better to have this condition after the URI matching.

> I am directed to my "cfm" page. That is *bad* because the shtml file
> is actually sitting in the filesystem.

This seem to be a problem with the the !-f (or your !-s) condition. I am not
very surprised, but if you could provide us with the rewrite log when you do
a request like this and also the *exact* rewrite directives used, it would
be much easier to tell how to fix it. See:
    http://httpd.apache.org/docs-2.0/mod/mod_rewrite.html#rewritelog

Regards,
Robert Andersson


---------------------------------------------------------------------
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] Please help me with this error document directive

Posted by Jon Block <ht...@collegepublisher.com>.
Hello Robert,

I am still stuck.. here is what I added inside my <virtualhost>.......

 ## Only continue if it is a request that can be handled AND if it doesn't
exist
 RewriteEngine On #turns on mod_rewrite
 RewriteCond %{REQUEST_FILENAME} !-s #checks to make sure file does not
exist
 RewriteCond %{REQUEST_URI}
^.*/news/[0-9]{4}/[0-9]{2}/[0-9]{2}/.+/.+\.shtml$ #checks to make sure the
request matches this pattern
 RewriteRule .* /main.cfm?include=detail [L] # Directs the user to a special
CFM page to handle the missing file.

Here is what I know from my testing so far...

If I request:

http://10.0.0.137/news/2003/02/06/ArtsAndEntertainment/testx.txt

There is no file named testx.txt and I get the default apache 404 error
returned to my browser. That's the desired behavior so thats good.

If I request:

http://10.0.0.137/news/2003/02/06/ArtsAndEntertainment/testx.shtml

I am directed to my "cfm" page. Thats good because the file is not there.

If I request:

http://10.0.0.137/news/2003/02/06/ArtsAndEntertainment/yayForSchool.shtml

I am directed to my "cfm" page. That is *bad* because the shtml file is
actually sitting in the filesystem. Just in case it matters, the path in the
filesystem is
M:\ding\news\2003\02\06\ArtsAndEntertainment\yayForSchool.shtml and the
"/news" in the URL maps to "M:\ding\news". Additionally, the "M:" drive
itself is a virtual drive (created with the subst utility in windows) which
points to "C:\mdrive".

Can you please let me know what it is you think I could be doing wrong? I am
stumped.

Thanks,
Jon


-----Original Message-----
From: Robert Andersson [mailto:robert@profundis.nu]
Sent: Wednesday, December 10, 2003 1:29 AM
To: users@httpd.apache.org
Subject: Re: [users@httpd] Please help me with this error document
directive


Jon Block wrote:
> Here are some URL's that should *not* hit my ErrorDocument directive....
>
> http://www.bbtp.com/news/2003/02/06/ArtsAndEntertainment
> http://www.bbtp.com/news/2003/02/06/ding/
> ...snip...
>
> Here are the url's that *should* hit my error handler
>
> http://www.bbtp.com/news/2003/02/06/yay/iofdios.shtml
> http://www.bbtp.com/news/2003/02/06/bling/doggy.shtml
> ...snip...

Perhaps it doesn't have to be an error document? If I understand your
requirements, this rewrite rule should do it:

    # VirtualHost context assumed
    RewriteEngine On
    # Only continue if it is a request that can be handled
    RewriteCond %{REQUEST_URI} ^/news/([0-9]+/){3}.+/.+\.shtml$
    # and only if it doesn't exist
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule .* /bling.cfm

I shortened the first pattern so it would fit on a line, but you may expand
it as you had it. You may also want to add the [R] flag to the last rule, so
it performs an external redirect to it. The original request is available in
the environment variable REQUEST_URI, or you could add it to the query
string of bling.cfm if you do an external redirect.

I have not tested it, but I have similar rules that work well. Joshua is the
mod_rewrite guru, so he may give some comments.

Regards,
Robert Andersson


---------------------------------------------------------------------
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] Please help me with this error document directive

Posted by Robert Andersson <ro...@profundis.nu>.
Jon Block wrote:
> Here are some URL's that should *not* hit my ErrorDocument directive....
>
> http://www.bbtp.com/news/2003/02/06/ArtsAndEntertainment
> http://www.bbtp.com/news/2003/02/06/ding/
> ...snip...
>
> Here are the url's that *should* hit my error handler
>
> http://www.bbtp.com/news/2003/02/06/yay/iofdios.shtml
> http://www.bbtp.com/news/2003/02/06/bling/doggy.shtml
> ...snip...

Perhaps it doesn't have to be an error document? If I understand your
requirements, this rewrite rule should do it:

    # VirtualHost context assumed
    RewriteEngine On
    # Only continue if it is a request that can be handled
    RewriteCond %{REQUEST_URI} ^/news/([0-9]+/){3}.+/.+\.shtml$
    # and only if it doesn't exist
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule .* /bling.cfm

I shortened the first pattern so it would fit on a line, but you may expand
it as you had it. You may also want to add the [R] flag to the last rule, so
it performs an external redirect to it. The original request is available in
the environment variable REQUEST_URI, or you could add it to the query
string of bling.cfm if you do an external redirect.

I have not tested it, but I have similar rules that work well. Joshua is the
mod_rewrite guru, so he may give some comments.

Regards,
Robert Andersson


---------------------------------------------------------------------
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] Please help me with this error document directive

Posted by Jon Block <ht...@collegepublisher.com>.
Hi Joshua,

Thank you so much for your help. I think you can probably help me solve
this... Let me try to be more clear and lets see if you can figure it out
for me...

For the following example, lets assume that all of the folders up to
http://www.bbtp.com/news/2003/02/06/ exist but the "06" folder is empty.

Here are some URL's that should *not* hit my ErrorDocument directive....

http://www.bbtp.com/news/2003/02/06/ArtsAndEntertainment
http://www.bbtp.com/news/2003/02/06/ding/
http://www.bbtp.com/news/2003/02/06/yay/iofdios.html
http://www.bbtp.com/news/2003/02/06/michaeljackson/iofdios/ifodisfds
http://www.bbtp.com/news/2003/02/06/beatit/iofdios/ifodisfds/iofdiosfds.shtm
l
http://www.bbtp.com/news/2003/02/06/punked/iofdios/ifodisfds/iofdiosfds.jpg

Here are the url's that *should* hit my error handler

http://www.bbtp.com/news/2003/02/06/yay/iofdios.shtml
http://www.bbtp.com/news/2003/02/06/bling/doggy.shtml
http://www.bbtp.com/news/2003/02/06/mickey/mouse.house.yay.for.me.shtml
http://www.bbtp.com/news/2003/02/06/mickey/objects-in-the-mirror-are-closer-
than-they-appear.shtml

Let me know what you think Joshua! Thanks again...

-Jon

-----Original Message-----
From: Joshua Slive [mailto:joshua@slive.ca]
Sent: Monday, December 08, 2003 12:31 PM
To: users@httpd.apache.org
Subject: Re: [users@httpd] Please help me with this error document
directive



On Mon, 8 Dec 2003, Jon Block wrote:
> Here is an example of an HTTP GET request I'm making on my Apache
server...
>
>
http://www.bbtp.com/news/2003/02/06/ArtsAndEntertainment/What.I.want.for.my.
> birthday.shtml

> I am trying to figure out how to tell Apache "If you get a request like
> this, serve out "/bling.cfm" instead. However, I only want to serve out
> "/bling.cfm" if the "ArtsAndEntertainment" folder is missing.

> <FilesMatch "X:/news/[0-9]{4}/[0-9]{2}/[0-9]{2}/.+/.+\.shtml$">
> 	ErrorDocument 404 /bling.cfm
> </FilesMatch>
>
> However, this doesn't work... i get a 404 error when i try my request.
> Please help!

Ummm... Aren't you TRYING to get a 404 error?  I guess you are saying you
are getting the INTERNAL 404 error rather than your page.

A couple issues here:

1. <FilesMatch> matches only filenames, not complete paths.

2. It is not very clear exactly what you are trying to accomplish.  It
could be clearer if you supplied a few example URLs that you want to hit
your error handler and a few that you don't.

3. Given that, here are a few guesses at what you want:

This should have very close to the affect that your <FilesMatch> was
trying to get:

<LocationMatch /news/[0-9]{4}/[0-9]{2}/[0-9]{2}/.+/.+\.shtml$">
ErrorDocument 404 /bling.cfm
</FilesMatch>

Another technique might be
<Directory X:/news/*/*/*/*/>
ErrorDocument 404 /blink.cfm
</Directory>
which tries to catch any missing file in the fourth level directory under
news.

If that isn't what you want, you need to be clearer in your problem
description.

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


---------------------------------------------------------------------
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] Please help me with this error document directive

Posted by Joshua Slive <jo...@slive.ca>.
On Mon, 8 Dec 2003, Jon Block wrote:
> Here is an example of an HTTP GET request I'm making on my Apache server...
>
> http://www.bbtp.com/news/2003/02/06/ArtsAndEntertainment/What.I.want.for.my.
> birthday.shtml

> I am trying to figure out how to tell Apache "If you get a request like
> this, serve out "/bling.cfm" instead. However, I only want to serve out
> "/bling.cfm" if the "ArtsAndEntertainment" folder is missing.

> <FilesMatch "X:/news/[0-9]{4}/[0-9]{2}/[0-9]{2}/.+/.+\.shtml$">
> 	ErrorDocument 404 /bling.cfm
> </FilesMatch>
>
> However, this doesn't work... i get a 404 error when i try my request.
> Please help!

Ummm... Aren't you TRYING to get a 404 error?  I guess you are saying you
are getting the INTERNAL 404 error rather than your page.

A couple issues here:

1. <FilesMatch> matches only filenames, not complete paths.

2. It is not very clear exactly what you are trying to accomplish.  It
could be clearer if you supplied a few example URLs that you want to hit
your error handler and a few that you don't.

3. Given that, here are a few guesses at what you want:

This should have very close to the affect that your <FilesMatch> was
trying to get:

<LocationMatch /news/[0-9]{4}/[0-9]{2}/[0-9]{2}/.+/.+\.shtml$">
ErrorDocument 404 /bling.cfm
</FilesMatch>

Another technique might be
<Directory X:/news/*/*/*/*/>
ErrorDocument 404 /blink.cfm
</Directory>
which tries to catch any missing file in the fourth level directory under
news.

If that isn't what you want, you need to be clearer in your problem
description.

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