query apache for rewrite/alias rules

query apache for rewrite/alias rules

am 18.09.2007 22:33:53 von ChronoFish

I know the answer is probably "No ", but I'm going to ask anyway.


Is there a way to query Apache for the system path of the file being
requested? (pre-rewrite - I'm not simply asking for a script name
here)


Here is what I want to do and why:

I have written a PHP script that allows a user to surf a Zip file in
the same way that apache serves up directory listings. I have a
rewrite rule that sends the requested file's URI path to my script.
This way anytime the user hits

http://localhost/somepath/myzip.zip

The request is re-written as

/projects/zipView/?file=somepath/myzip.zip&path=


The script returns the contents of the first level directory in the
zip file. If the user clicks on a zipped sub directory, the URL looks
like:

http://localhost/somepath/myzip.zip/contents

and the rewrite rule produces

/projects/zipView/?file=somepath/myzip.zip&path=/contents


All of this works great and as I want it to.

The trick is that there are alias directories. For example "backup"
is mapped to "c:\systemBackup\archive1". The rewrite rule still
works, but it the script tries to grab the wrong directory.


For instance:

http://localhost/backup/2007_09_20/contents.zip

is rewritten

/projects/zipView/?file=backup/2007_09_20/contents.zip&path

However, "backup" is an alias for the directory "c:\systemBackup
\archive1" rather than DOCUMENT_ROOT\backup\


So what I would like is a way to ask Apache for the real directory of
the request /backup.

I could parse the Apache Config file, but that gets tricky once you
start using AliasMatch (regular expressions) not to mention dealing
with multiple included config files.


NOTE: This is a WAMP environment. If this were a LAMP environment
there would be no issue - I would create a symbolic or hard link.

Any thoughts?

Thanks!
CF

Re: query apache for rewrite/alias rules

am 18.09.2007 23:45:40 von HansH

"ChronoFish" schreef in bericht
news:1190147633.150068.158140@n39g2000hsh.googlegroups.com.. .
> The script returns the contents of the first level directory in the
> zip file. If the user clicks on a zipped sub directory, the URL looks
> like:
> http://localhost/somepath/myzip.zip/contents
> and the rewrite rule produces
> /projects/zipView/?file=somepath/myzip.zip&path=/contents
>
> The trick is that there are alias directories. For example "backup"
> is mapped to "c:\systemBackup\archive1". The rewrite rule still
> works,
BEFORE the alias kicked in ...

> but it the script tries to grab the wrong directory.
.... THUS the script is misguided

> http://localhost/backup/2007_09_20/contents.zip
> is rewritten
> /projects/zipView/?file=backup/2007_09_20/contents.zip&path
>
> However, "backup" is an alias for the directory "c:\systemBackup
> \archive1" rather than DOCUMENT_ROOT\backup\
>
When mod_alias and mod_rewrite interfere mostly the [PT] flag will save your
day ... guts feeling not this time :|

> NOTE: This is a WAMP environment. If this were a LAMP environment
> there would be no issue - I would create a symbolic or hard link.
http://www.microsoft.com/technet/sysinternals/FileAndDisk/Ju nction.mspx
Windows 2000 and higher supports directory symbolic links, where a directory
serves as a symbolic link to another directory on the computer. ...

You may try your luck with the utility downloadable at the same page.

HansH

Re: query apache for rewrite/alias rules

am 19.09.2007 00:09:10 von ChronoFish

On Sep 18, 4:33 pm, ChronoFish wrote:
> I know the answer is probably "No ", but I'm going to ask anyway.
>
> Is there a way to query Apache for the system path of the file being
> requested? (pre-rewrite - I'm not simply asking for a script name
> here)
>
> Here is what I want to do and why:
>
> I have written a PHP script that allows a user to surf a Zip file in
> the same way that apache serves up directory listings. I have a
> rewrite rule that sends the requested file's URI path to my script.
> This way anytime the user hits
>
> http://localhost/somepath/myzip.zip
>
> The request is re-written as
>
> /projects/zipView/?file=somepath/myzip.zip&path=
>
> The script returns the contents of the first level directory in the
> zip file. If the user clicks on a zipped sub directory, the URL looks
> like:
>
> http://localhost/somepath/myzip.zip/contents
>
> and the rewrite rule produces
>
> /projects/zipView/?file=somepath/myzip.zip&path=/contents
>
> All of this works great and as I want it to.
>
> The trick is that there are alias directories. For example "backup"
> is mapped to "c:\systemBackup\archive1". The rewrite rule still
> works, but it the script tries to grab the wrong directory.
>
> For instance:
>
> http://localhost/backup/2007_09_20/contents.zip
>
> is rewritten
>
> /projects/zipView/?file=backup/2007_09_20/contents.zip&path
>
> However, "backup" is an alias for the directory "c:\systemBackup
> \archive1" rather than DOCUMENT_ROOT\backup\
>
> So what I would like is a way to ask Apache for the real directory of
> the request /backup.
>
> I could parse the Apache Config file, but that gets tricky once you
> start using AliasMatch (regular expressions) not to mention dealing
> with multiple included config files.
>
> NOTE: This is a WAMP environment. If this were a LAMP environment
> there would be no issue - I would create a symbolic or hard link.
>
> Any thoughts?
>
> Thanks!
> CF

Here is the answer to my question:

You can pass %{REQUEST_URI} through the rewrite rule which gives the
file-system target. Made a tiny change in my script to accommodate
and everything is good.

Thanks,
CF