trouble mapping fileName.php to fileName.php.dev

New to mod_rewrite? This is a good place to start.

trouble mapping fileName.php to fileName.php.dev

Postby JasonK » Mon Nov 03, 2003 4:22 pm

I am having some troubles doing something that should be fairly easy. I wan't any request for fileName.php to look if fileName.php.dev exists, if it does, then serve up that file, othewise server up fileName.php. Here is my code:
Code: Select all
# use mod-rewrite for development.  If this is the development server,
#look
# for FileName.php.dev when FileName.php is requested, if
#FileName.php.dev
# does not exist, then use FileName.php.
RewriteRule   ^(.*)\.php$              $1      [C,E=isPHP:yes]
# check to see if FileName.php.dev exists
RewriteCond   %{REQUEST_FILENAME}.dev -f
# FileName.php.dev does exist, so redirect to it
RewriteRule   ^(.*)$ $1.php.dev                   [S=1]
# FileName.php.dev does not exist, so try to revert to the originally
# requested file
RewriteCond   %{ENV:isPHP}            ^yes$
RewriteRule   ^(.*)$ $1.php


The code is nearly identical to the example at http://httpd.apache.org/docs/misc/rewriteguide.html for
Backward Compatibility for YYYY to XXXX migration


The problem seem sdo be the RewriteCond %{REQUEST_FILENAME}.dev -f isn't evaluating to TRUE when it should be.

I have some other rewrite rules above this, so I am not sure if that requires me to do anything differently. For instance, I assume I still reference $1 as the first pattern matched, even though I have another $1 in the previous rule (which doesn't use the [C] chain directive).

Is there a good way to print out the value of %{REQUEST_FILENAME}?

Thanks!!!!
JasonK
 

Postby JasonK » Tue Nov 04, 2003 8:18 am

I got it to work finally. It was a combination of things.
1) I didn't have the re-write base set, so it was inserting the entire htdocs path into the new url.
2) %{REQUEST_FILENAME} does not contain the extension, so I had to add the extension in the filename check.
Here was my end result:

Code: Select all
   RewriteEngine on
   RewriteBase    /www/socdev/docs

       # use mod-rewrite for development.  If this is the development server, look
    # for FileName.php.dev when FileName.php is requested, if FileName.php.dev
    # does not exist, then use FileName.php.
    RewriteRule   ^(.*)\.php$              $1      [C,E=isPHP:yes]
    # check to see if FileName.php.dev exists
    RewriteCond   %{REQUEST_FILENAME}.php.dev -f
    # FileName.php.dev does exist, so redirect to it
    RewriteRule   ^(.*)$ /$1.php.dev                   [S=1]
    # FileName.php.dev does not exist, so try to revert to the originally requested file
    RewriteCond   %{ENV:isPHP}            ^yes$
    RewriteRule   ^(.*)$ $1.php [L]
JasonK
 


Return to Beginner's Corner

Who is online

Users browsing this forum: No registered users and 67 guests

cron