Apache Server configuration support - URL testing with mod_rewrite

This is Interesting: Free IT Magazines  
Home > Archive > Apache Server configuration support > January 2007 > URL testing with mod_rewrite





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author URL testing with mod_rewrite
Csaba Gabor

2007-01-09, 7:28 pm

Is there any way that I can test to find out if a given URL request
would be handled by apache, and if so what the full URL would be (all
under the same domain)?

E.g. suppose I receive: http://mydomain.com/
Within mod_rewrite, I'd like to test wether that URL will be handled
(but not handle it), and if so, return the (dfault) file that leads to
it being handled, such as http://mydomain.com/index.php or
http://mydomain.com/index.htm

Or, http://mydomain.com/some/path/
Would this be handled (but don't handle it yet), and if so what is the
complete URL (http://mydomain.com/some/path/index.php or
http://mydomain.com/some/path/index.htm)

Thanks for any tips,
Csaba Gabor from Vienna

Davide Bianchi

2007-01-10, 7:22 am

On 2007-01-09, Csaba Gabor <danswer@gmail.com> wrote:
> Is there any way that I can test to find out if a given URL request
> would be handled by apache, and if so what the full URL would be (all
> under the same domain)?


What do you mean with 'be handled by apache' ? Every URL that is
received is going to be handled, what is going to be the result of
such 'handling' is another matter.

You could test if there is a file or a directory matching the URL, but
that doesn't mean anything in term of 'handling'.

Be more specific please.

Davide

--
System Administration is like the toilet's sink: if it works, you don't
even know that is there, if it doesn't, you're in _real_ shit.
-- myself
Csaba Gabor

2007-01-10, 7:22 am

Davide Bianchi wrote:
> On 2007-01-09, Csaba Gabor <danswer@gmail.com> wrote:
>
> What do you mean with 'be handled by apache' ? Every URL that is
> received is going to be handled, what is going to be the result of
> such 'handling' is another matter.
>
> You could test if there is a file or a directory matching the URL, but
> that doesn't mean anything in term of 'handling'.
>
> Be more specific please.


You're correct, and it seems you've guessed my meaning. I actually
meant that I want to test whether there is a file (under a normal
status code) that corresponds to a given "stripped" URL (taking into
account that using DirectoryIndex will map a directory to a file, if
one of the specified file types exist). And stripped URL means that
any PATH_INFO along with any ?foo=bar&baz=... has been stripped.

Maybe another way to state my problem (I think) is to ask whether a
"non error page" will result, and if so, what is the corresponding
file?

If this is not clear enough, let me know.
Sorry for my terminology - it's been a while since I worked with
apache.
Thanks,
Csaba

Davide Bianchi

2007-01-10, 7:22 am

On 2007-01-10, Csaba Gabor <danswer@gmail.com> wrote:
> Maybe another way to state my problem (I think) is to ask whether a
> "non error page" will result, and if so, what is the corresponding
> file?


You could test if the requested file exists, but ain't
much easier to act on the opposite? That is, just use a custom
404 page to 'catch' the non-existence of the requested document.

Davide

--
If I held you any closer I'd be on the other side of you.
-- Julius Henry "Groucho" Marx (http://en.wikiquote.org/wiki/Groucho_Marx)
Csaba Gabor

2007-01-10, 7:22 am

Davide Bianchi wrote:
> On 2007-01-10, Csaba Gabor <danswer@gmail.com> wrote:
>
> You could test if the requested file exists, but ain't
> much easier to act on the opposite? That is, just use a custom
> 404 page to 'catch' the non-existence of the requested document.


I don't think so, if I've understood you correctly. Let me give a
concrete example.
Suppose the request comes in for
http://mydomain.com/something/extra
and I have index.php in the document root
and I have DirectoryIndex set to index.php index.htm index.html

Of course the above request should fail (assume that there is no
'something' subdirectory off the web root). However, if any of the
three DirectoryIndex files exist in the root directory, I would like
that file name to be inserted. In the above example, the url should be
(effectively) rewritten to
http://mydomain.com/index.php/something/extra and then path_info could
take over from there. So for this to work in the way that I outline, I
can't test for non-existence since that won't give me the name of the
actual file that will be used.

Csaba

Davide Bianchi

2007-01-10, 7:22 am

On 2007-01-10, Csaba Gabor <danswer@gmail.com> wrote:
> Suppose the request comes in for http://mydomain.com/something/extra
> and I have index.php in the document root
> and I have DirectoryIndex set to index.php index.htm index.html
> Of course the above request should fail (assume that there is no
> 'something' subdirectory off the web root). However, if any of the
> three DirectoryIndex files exist in the root directory, I would like
> that file name to be inserted. In the above example, the url should be
> (effectively) rewritten to
> http://mydomain.com/index.php/something/extra and then path_info could


I don't think there is a way to do so with mod_rewrite, you should catch
the 404 error into a personalized script (php or wathever) and then
apply wathever trickery in there.

Davide

--
Behind every successful man is a woman, behind her is his wife.
-- Julius Henry "Groucho" Marx (http://en.wikiquote.org/wiki/Groucho_Marx)
Csaba Gabor

2007-01-11, 1:32 pm

Davide Bianchi wrote:
> On 2007-01-10, Csaba Gabor <danswer@gmail.com> wrote:
>
> I don't think there is a way to do so with mod_rewrite, you should catch
> the 404 error into a personalized script (php or wathever) and then
> apply wathever trickery in there.


I'm not yet convinced that this is a dead horse, but I am running into
a problem even before I get to the meat. I figured to first test
whether the original URL resolved (never mind WHAT it resolves to) with
something like:

RewriteCond %{IS_SUBREQ} false
RewriteCond %{ENV:SCRIPT_URI} -U
RewriteRule . - [L,E=RewriteTesting:%{SCRIPT_FILENAME}]

I tested with the following 5 valid urls (where the root has a
subdirectory: path; path contains index.php; and DirectoryIndex is set
to index.php index.htm index.html):

mydomain.com/path
mydomain.com/path/
mydomain.com/path/index.php
mydomain.com/path/index.php/
mydomain.com/path/index.php/foo

In the last two cases, RewriteTesting is set correctly, but the 2nd
rewrite cond fails in the first three cases. However, I noted that
there wre sub requests in the first two cases. Motivated by this, I
changed the middle RewriteCond to:

RewriteCond %{REQUEST_URI} -U

and then all 5 cases work as expected. So it seems like what might be
going on is that the environment of subrequests is wiped (somewhat)
clean. That still doesn't explain the middle case, though. Ahh, well,
just thought I'd share some notes. Contributory comments are welcome.

Csaba Gabor from Vienna

Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2009 webservertalk.com