Tricky RewriteCond / LA-U:SCRIPT_FILENAME situation

This is a discussion on Tricky RewriteCond / LA-U:SCRIPT_FILENAME situation within the Apache Web Server forums, part of the Web Server and Related Forums category; I would like to determine whether a certain URI resolves to a file and (if so) what that file is. ...


Go Back   Usenet Forums > Web Server and Related Forums > Apache Web Server

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 01-14-2007
Csaba Gabor
 
Posts: n/a
Default Tricky RewriteCond / LA-U:SCRIPT_FILENAME situation

I would like to determine whether a certain URI resolves to a file and
(if so) what that file is. The following seems to do the trick.

#Look ahead to see how the request resolves
RewriteCond %{LA-U:SCRIPT_FILENAME} ^(.*)$
#If it resolved to a file, assume it's OK
RewriteCond %1 -f

However, this breaks down when I've got URL rewriting going on, but I
don't see how to fix it up. Specifically, given a request,
mydomain.com/path1/path2/path3, if it doesn't resolve to a document,
I'd like apache to determine the deepest subdirectory and then
determine whether there is an index file in that directory.

The first step is to resolve the incoming URI with
LA-U:SCRIPT_FILENAME, which works fine. The next step is to find the
deepest subdirectory with a loop. Works fine, too. It fails on the
next to the last line because LA-U:SCRIPT_FILENAME does not return with
index.php at the end - perhaps someone can spot whether I'm doing
something wrong (same story with REQUEST_FILENAME in place of
SCRIPT_FILENAME):

# Initial test to see whether original request resolves.
# Only entered first time through (controlled by State)
RewriteCond %{IS_SUBREQ} false
RewriteCond %{ENV:State} !.
# What does the filename resolve to?
RewriteCond %{LA-U:SCRIPT_FILENAME} ^(.*)$
# If it resolves to a file, then we're done
RewriteCond %1 -f
RewriteRule . - [E=RewriteDone:%1,L]

# Initialize the loop to find the deepest directory
# Only entered first time through (controlled by Sfx)
RewriteCond %{IS_SUBREQ} false
RewriteCond %{ENV:Sfx} !.
RewriteRule ^(.*)(/[^/]*.)$ - [E=Pfx:$1,E=Sfx:$2,E=State:Part2]

# Loop to find deepest directory - one must exist
# since the root directory exists
RewriteCond %{IS_SUBREQ} false
RewriteCond %{ENV:State} Part2
# If it's a directory, then go on to next section
RewriteCond %{DOCUMENT_ROOT}%{ENV:Pfx}/ !-d
# Otherwise, pop up one level
RewriteCond %{ENV:Pfx} ^(.*)(/[^/]*)$
# By doing a rewriting
RewriteRule ^.+$ %1 [E=Pfx:%1,E=Sfx:%2%{ENV:Sfx},N]

# This section checks for an index file at this deepest directory
RewriteCond %{IS_SUBREQ} false
RewriteCond %{ENV:State} Part2
# This should do the checking, but fails
RewriteCond %{LA-U:REQUEST_FILENAME} ^(.*)$
# Now check whether it resolved to a filename
RewriteCond %1 -f
# And if so append the pathinfo to such fully resolved filename
RewriteRule ^.+ %1%{Env:Sfx} [L]



If more details or explanations are needed, please let me know.
Thanks,
Csaba Gabor from Vienna

 


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 06:08 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0