Issue with SCRIPT_FILENAME in a RewriteCond

Oh, the strange things mod_rewrite does!

Issue with SCRIPT_FILENAME in a RewriteCond

Postby kellygreer1 » Mon Sep 08, 2008 2:02 pm

I have a root folder with too subfolder paths
1) /app/webroot/
2) /oldapps/

Lets say for example I have an application called contacts in "/oldapps/contacts" all other requests should be routed to /app/webroot/
I'm trying to use this set of rules in an .htaccess file.

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^contacts$ oldapps/contacts/ [L]
RewriteRule ^contacts\/(.*) oldapps/contacts/$1 [L]
RewriteRule ^$ app/webroot/ [L]
RewriteCond %{SCRIPT_FILENAME} !oldapps\/.*
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>

This works great until you throw a weird URL at the server that contains the text "oldapps" but is down the /contacts/ path. examples:
http://localhost/contacts/oldapps/

Why didn't the developers of mod_rewrite give you the option to use SCRIPT_NAME instead of SCRIPT_FILENAME ?
I'm developing on Windows deploying on Linux? SCRIPT_FILENAME does not seem very portable. If I could use SCRIPT_NAME I could write the RewriteCond like so:

RewriteCond %{SCRIPT_NAME} !^\/oldapps\/.*

Without this I can't use the ^ character....
Any ideas on how I can write this better? I'd like to keep the code in the .htaccess file.
Thanks,
KellyGreer1
kellygreer1
 
Posts: 1
Joined: Mon Sep 08, 2008 1:47 pm

Postby richardk » Wed Sep 10, 2008 10:04 am

Can't you use REQUEST_URI?

Or try
Code: Select all
Options +FollowSymLinks

<IfModule mod_rewrite.c>
  RewriteEngine On

  RewriteRule ^contacts(/(.*))?$ /oldapps/contacts/$2 [L]

  # Doesn't match if mod_rewrite has already run for this request.
  RewriteCond %{ENV:REDIRECT_STATUS} ^$
  RewriteRule ^(.*)$ /app/webroot/$1 [L]
</IfModule>
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Idiosyncrasies

Who is online

Users browsing this forum: No registered users and 7 guests

cron