Tyler Muth’s Blog

Technology with a focus on Oracle, Application Express and Linux

mod_rewrite and APEX

Posted by Tyler Muth on August 12, 2008

I’m working on a publication and one concept I’d like to include is the use of mod_rewrite and APEX as it helps simplify another concept.  Here’s the problem, while I’ve used mod_rewrite in many production environments, I’ve never used the exact concept I want to write about.  Essentially, I want to force all requests for the APEX development environment through one Database Access Descriptor (DAD), and all requests for other applications to a different DAD.

I’ve written and tested the rules for this, but I’m asking for some help from the community to check my work and offer suggestions. Sorry, I’m not offering money, or even recognition in the publication (it’s something I cant commit to), but I will definitely acknowledge it here if someone catches an error of mine or makes a suggestion that I use.

So, my goal is to force all requests for “apex”, “apex_admin”, and f?p=4xxx to the “builder” DAD, while forcing all requests to f?p= (anything other than 4000-4999) to the “apex” DAD.

RewriteEngine on
Options +FollowSymLinks
#RewriteLog "/tmp/rewrite.log"
#RewriteLogLevel 3

# Change all requests for "apex" shortcuts to the builder DAD
RewriteRule /pls/apex/apex /pls/builder/apex [R]
RewriteRule /pls/apex/apex_admin /pls/builder/apex_admin [R]

# Change all 4000s to builder DAD
RewriteCond %{REQUEST_URI}%{QUERY_STRING} /pls/apex/f?p=(4[0-9]{3}:.*)
RewriteRule /pls/apex/ /pls/builder/f?p=%1 [R,L]

# Change 4, 40-49, 400-499, or any number starting with 4 greater than 40000 to apex DAD
RewriteCond %{REQUEST_URI}%{QUERY_STRING} /pls/builder/f?p=((4[0-9]{0,2}:)|(4[0-9]{4,}:))
RewriteRule /pls/builder/ /pls/apex/f?p=%1 [R]

# Change all numbers not starting with 4 to apex DAD
RewriteCond %{REQUEST_URI}%{QUERY_STRING} /pls/builder/f?p=(([1-3]|[5-9])[0-9]*:.*)

2 Responses to “mod_rewrite and APEX”

  1. Tyler Muth said

    Thanks to some feedback from Christopher Beck, I changed line 9 such that it includes all numbers from 1-3999 and 5000-infinity. My original line only had numbers 100-3999 and 5000-infinity. Since it might be possible to create an app with a number less than 100, best to play it safe. Original line 9:
    RewriteCond %{REQUEST_URI}%{QUERY_STRING} /pls/builder/f?p=(([1-3]|[5-9])[0-9]{2,}:.*)
    New line 9:
    RewriteCond %{REQUEST_URI}%{QUERY_STRING} /pls/builder/f?p=(([1-3]|[5-9])[0-9]{0,}:.*)
    Note the change from …{3,}… meaning “2 or more” to …{0,}…, meaning “0 or more”. Thanks Chris!

  2. Christopher Beck said

    Tyler,

    Couldn’t the [0-9]{0,}* in Line 9 just be [0-9]* since * indicates “zero or more”.

    Also, I don’t see the ranges for 4, 40-49 and 400-499 represented?!?!

    If I read your current rules correctly

    Line 7 – the 4000s
    Line 9 – any number that does not start with a 4
    Line 11 – any number thats start with 4 that is 40000 or greater

    How about this?

    # Change all 4000s to builder DAD
    RewriteCond %{REQUEST_URI}%{QUERY_STRING} /pls/apex/f?p=(4[0-9]{3}:.*)
    RewriteRule /pls/apex/ /pls/builder/f?p=%1 [R]

    # Change 4, 40-49, 400-499, or any number starting with 4 greater than 40000 to apex DAD
    RewriteCond %{REQUEST_URI}%{QUERY_STRING} /pls/builder/f?p=(4[0-9]{0,2}|4[0-9]{4,}:.*)
    RewriteRule /pls/builder/ /pls/apex/f?p=%1 [R]

    # Change all numbers not starting with 4 to apex DAD
    RewriteCond %{REQUEST_URI}%{QUERY_STRING} /pls/builder/f?p=(([1-3]|[5-9])[0-9]*:.*)
    RewriteRule /pls/builder/ /pls/apex/f?p=%1 [R]

    chris.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: