//
you're reading...
Oracle APEX, Oracle HTTP

Apache Rewrite for Oracle Apex Application


You would usually use Apache rewrite to assign a more friendly URL for APEX app. I have these config that has been working great for me.

This work for apex flash chart too

UPDATE as at 13 August 2012

Apparently for apex flash chart, it is NOT gonna work. You are gonna hit the Flash Security Error. I am still trying to find the solution.

<VirtualHost *:80>

ServerName finance-app.mydomain.com
 ServerAlias finance-app
 RewriteEngine On
 RewriteRule ^/$ http://oracle01:7777/pls/apex/f?p=134 [L,P]

RewriteCond %{QUERY_STRING} ^(.*)oracle01:7777.*flash(.*)$
 RewriteRule ^/(.*) /$1?%1finance-app/apex_util.flash%2 [L,R]

RewriteRule ^/i/(.*) http://oracle01:7777/i/$1 [L,P]
 RewriteRule ^/c/(.*) http://oracle01:7777/c/$1 [L,P]
 RewriteRule ^/data/(.*) http://oracle01:7777/data/$1 [L,P]

RewriteCond %{QUERY_STRING} ^p=\d+:101$
 RewriteRule ^/ http://finance-app/ [L=310]

RewriteRule ^/(.*) http://oracle01:7777/pls/apex/$1 [L,P]

ErrorLog /var/log/finance-app-error_log
 TransferLog /var/log/finance-app-access_log
 RewriteLog /var/log/finance-app-rewite_log

</VirtualHost>

finance-app is the name of my application, which I want to access it using http://finance-app

oracle01 is my oracle http server that’s hosting oracle APEX

The URL http://oracle01:7777/pls/apex , /i/, and /c/, and /data/ will depend on your dads.conf file under your oracle http server.

Here is the content of my dads.conf

Alias /i/ "/oracle/product/APEX/apex_default_images/"
 Alias /c/ "/oracle/product/APEX/apex_custom_files/"
 Alias /data/ "/oracle/product/APEX/AppData/"

AddType text/xml xbl
 AddType text/x-component htc

<Location /pls/apex>
 Order deny,allow
 PlsqlDocumentPath docs
 AllowOverride None
 PlsqlDocumentProcedure wwv_flow_file_mgr.process_download
 PlsqlDatabaseConnectString oracledb.mydomain.com:1521:APEXDB ServiceNameFormat
 PlsqlNLSLanguage AMERICAN_AMERICA.AL32UTF8
 PlsqlAuthenticationMode Basic
 SetHandler pls_handler
 PlsqlDocumentTablename wwv_flow_file_objects$
 PlsqlDatabaseUsername APEX_PUBLIC_USER
 PlsqlDefaultPage apex
 PlsqlDatabasePassword apexpubuser
 Allow from all
 </Location>

I hope this posting helps whoever needed a friendlier URL for APEX app.

Advertisements

About Yoel Susanto

Oracle Specialist

Discussion

21 thoughts on “Apache Rewrite for Oracle Apex Application

  1. I will give it a try this weekend and tell you how it went, Thank you very much!

    PD: Does it work with the flash charts in the end or not?

    Posted by Aldo | August 23, 2012, 9:08 PM
  2. Hi Aldo,

    I haven’t been able to get this to work with flash chart. You’ll get the Flash Security Error.
    The solution for this is to put cross-domain policy file in the root directory of your http server.
    You can see the detail here http://www.anychart.com/products/anychart/docs/users-guide/index.html
    Expand the “Implementation” and click on “Security Error”.

    I could have swore that this work before, my best assumption is that it’s stopped working when we upgraded to Apex 4. It may be due to the newer version of AnyChart engine for apex 4 has a tighter security policy.

    Thank you for reading my blog! Let me know if you have other question.

    -Yoel

    Posted by Yoel Susanto | August 24, 2012, 10:13 AM
  3. Thank God we are not using the Charts on this application. But I guess its good to know the way to fix it.

    Right now I am trying to make it work on our app….

    Posted by Aldo | August 28, 2012, 9:06 AM
  4. Ok, It is not working for me at all….

    So, After I finished with the VirtualHost Configuration, I ended up with something like this:

    ServerName myapp.mydomain.com
    ServerAlias myapp_alias
    RewriteEngine On
    RewriteRule ^/$ http://www.mydomain.com:7777/pls/apex/f?p=104 [L,P]

    RewriteCond %{QUERY_STRING} ^(.*)www.mydomain.com:7777.*flash(.*)$
    RewriteRule ^/(.*) /$1?%1myapp_alias/apex_util.flash%2 [L,R]

    RewriteRule ^/i/(.*) http://www.mydomain.com:7777/i/$1 [L,P]

    RewriteCond %{QUERY_STRING} ^p=\d+:101$
    RewriteRule ^/ http://myapp_alias/ [L=310]

    RewriteRule ^/(.*) http://www.mydomain.com:7777/pls/apex/$1 [L,P]

    ErrorLog /var/log/myapp_alias-error_log
    TransferLog /var/log/myapp_alias-access_log
    RewriteLog /var/log/myapp_alias-rewite_log

    (I did not add the /c/ and /data/ cause my dads.conf did not contain these values)

    I tried to go on my application by using http://myapp_allias.com … but it did not work… the only way to access it is by http://www.mydomain.com/7777/pls/apex/f?p=104

    What might be the problem?

    Is this solution supposed to work just for intranets? or it also works for “public” apps….? (mine is a public one)

    I hope you can help me out with this situation.

    Thank you

    Aldo

    Posted by Aldo | August 28, 2012, 9:17 AM
    • HI Aldo,

      What do you get when you ping myapp_alias?
      It needs to point to the ip address of the server which you use to perform rewrite.

      I think the configuration should work for public app as well.

      Posted by Yoel Susanto | August 28, 2012, 2:13 PM
  5. Thanks Yoel,

    Let me give it a shot and I will post the results…

    Posted by Aldo | August 28, 2012, 11:10 PM
  6. I can ping the myapp_alias… I get the normal response (it’s up and working)
    However, even if I can get a normal response from the ping… the only way to access the app is by using the full address…. it does not work if I just use the just the myapp_alias on the address bar

    PS: I also tried this one

    ServerName http://www.myhost.com
    ServerAlias http://www.myhost.com
    RewriteEngine On
    RewriteRule ^/$ /pls/apex/f?p=136:1 [R=301]

    Posted by Aldo | August 29, 2012, 1:49 AM
  7. When you said full address, do you mean http://myapp_alias:7777//pls/apex/f?p=104?
    If that works, it looks like you are configuring your virtual host in the same machine as your OHS.
    Can you confirm this?

    If that’s the case, you need to assign your OHS to listen to port 80 as well beside 7777
    Because when you type http://myapp_alias in the browser, it will send the request to port 80. If your OHS is not listening to port 80, you’ll get an error. What error did you get btw?

    My configuration is different, I am using a different server to server the virtual host:
    1. I have my OHS running together with my database in server oracle01. My OHS is listening on port 7777
    2. I have apache running on different machine for the virtual host. This apache is listening on port 80
    3. I have my URL ‘finance-app’ pointing to the apache server (#2) not to my OHS (#1)
    4. So when I type in http://finance-app, the request will go to server #2 and then redirected to server #1.

    WIth my setup, if I ping ‘finance-app’ i’ll get ip address of server #2, not my OHS (server #1).

    Let me know. Thanks Aldo!

    Posted by Yoel Susanto | August 29, 2012, 11:02 AM
    • Tres bien… That was the problem… I was doing everything on one server, not 2 different servers…

      But still… no solution for my problem. I will keep working on it during the week, I will let you know if I figure out something.

      Its kind of frustrating… specially cause the OTN people always tell me “That has nothing to do with apex…” But apex doesnt offer an Out-Of-The-Box Solution for this…

      Anyway… I will keep working on this

      Thanks Yoel!

      Posted by Aldo | September 3, 2012, 1:26 AM
      • Aldo, it can still be done with the same server.

        1. You need to make your OHS listen to port 80 as well. You can update the httpd.conf file to do that.
        Restart OHS after editing the file. You can check whether the server is listening to port 80 by entering
        http://servername:80 in your browser
        2. Let say you store your virtual host config file in /etc/apache2/vhost/myapp.conf,
        You need to set OHS to read your virtual host config file by adding this line
        “Include /etc/apache2/vhost/myapp.conf” (without the double quote) into your httpd.conf
        Restart OHS and test the rewrite rule.

        Hopefully this helps.

        Posted by Yoel Susanto | September 3, 2012, 10:45 AM
  8. Got it, I will give it a try in the morning (we have almost 12 hours of difference)

    Thanks for your help!

    Posted by Aldo | September 3, 2012, 11:07 AM
  9. Im frustrated already… Ive changed everything but it is still not working… I double checked that the server was actually listening to the port 80…

    But its like, it’s just not considering the virtualhost configuration at all…

    Just asking, where is your httpd.cong located at?…. Maybe I am configuring the wrong one?

    I am just flipping out here hahaahah

    Thanks for your help

    Posted by Aldo | September 6, 2012, 3:47 AM
  10. Ok youre not gonna beleive this… The firewall was blocking the port 80 Hahahahahah!!!

    Its all working now

    Thank you so much for your help Yoel, you rock!

    Aldo

    Posted by Aldo | September 6, 2012, 10:12 AM
  11. Hi Yoel,
    Everythink work fine … Well almost everythink except logout from Apex 😉 When i try logout from app the browsers says:

    Not Found

    The requested URL /pls/apex/pls/apex/f was not found.

    Do you have the same behaviour in your app?

    Error log and rewrite log nothing catch…
    Just access log:
    [09/Oct/2012:17:41:46 +0200] “GET /apex_authentication.logout?p_app_id=105&p_session_id=4758237370201 HTTP/1.1” 302 –
    [09/Oct/2012:17:41:46 +0200] “GET /wwv_flow_custom_auth_std.logout?p_this_flow=105&p_next_flow_page_sess=105:1 HTTP/1.1″$
    [09/Oct/2012:17:41:46 +0200] “GET /pls/apex/f?p=105:1 HTTP/1.1” 404 202
    [09/Oct/2012:17:41:46 +0200] “GET /favicon.ico HTTP/1.1” 404 203

    Posted by Filip | October 9, 2012, 11:55 PM
    • Hi Filip,

      Looks like your logout page is not set to 101 (the login screen).
      Go to “Shared Component” –> “Authentication Schemes” and edit your current scheme.
      Make sure the “Logout URL” go to page 101

      Mine looks like the following

      wwv_flow_custom_auth_std.logout?p_this_flow=&APP_ID.&p_next_flow_page_sess=&APP_ID.:101

      Posted by Yoel Susanto | October 10, 2012, 11:24 AM
  12. Hello,
    Thanks for sharing your knowledge. I have no idea about Apache. Is there a way to rewrite the URL with Glassfish server ?

    Regards,

    Posted by fateh | June 25, 2013, 3:20 AM
    • Hi Fateh,

      Thank you for reading my blog.
      Unfortunately I am not familiar with Glassfish server and I think Glassfish is application server instead of web server like apache, so I am not sure if that’s possible.
      Setting up apache for the rewrite is a breeze, once installed you don’t need to change any of the default parameter to get the rewrite to work.
      You only have to make sure the apache read your application conf file you created.

      Hope this helps!

      cheers

      Posted by Yoel Susanto | June 25, 2013, 12:00 PM
  13. Hi Yoel

    Can you please help me set this up for https (port 443). It works well with http (port 80).

    Thanks

    Posted by pvc | August 9, 2013, 7:57 AM
  14. Hi PVC,

    I have not tried doing this using https protocol before and I am in a tight project deadline now.
    Can I get back to you once I figure it out?

    Thanks.

    Posted by Yoel Susanto | August 12, 2013, 1:06 PM

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 )

Google+ photo

You are commenting using your Google+ 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 )

Connecting to %s

Advertisements
%d bloggers like this: