hrURL – human readable URLs in Oracle APEX

Searching the APEX Forum for nice URLs is as old as Oracle APEX itself, so far without much luck. There is magic switch that forces APEX to create readable URLs.

As part of preparing my Presentation “Going Public” for Kscope 2014 in Seattle, I investigated the available methods on providing readable URLs and found some good ones.

You can check this public APEX website to see how good URLs can look like: www.click-click.at

This will be a series of 3 blogposts, to be published before/around christmas 2013.

If you are not familiar with the APEX URL Syntax, I recommend your read this blogpost or check the documentation at first.

Public Applications, only!

Yeah, sorry for that. For now the methods described in here mostly work for public applications only. That means, it does not work for applications you have to log on for.

Of course, that shouldn’t bother us at all. Nice URLs are unnecessary for internal applications (e.g. nobody bothers what the URL for your online banking site looks like).

From the Start

The APEX URL looks something like this: myserver/apex/f?p=123:45:67897878787

Not very nice, not easy to read and not easy to remember. And also not very good for bookmarking or search-robots. Read Jeff’s Blogpost on the Googlebot.

APEX Session Zero

To avoid problems with search robots and to have bookmarkable URLs, APEX introduced the very special Session ID 0 (as in zero). Using that, our URL starts looking better: myserver/apex/f?p=123:45:0

Alias

In APEX you can define an Alias for an Application and an Alias for Pages, which can be used in the URL instead of the IDs. That would change our URL to myserver/apex/f?p=URLTEST:HOME:0

In all kind of Branches, Button Targets, Column Links and so on you can put the Page Alias, but you cannot change the URL to use the Application Alias.

Unfortunately APEX doesn’t care if you use an Alias to run the application, it will create all succeeding links using IDs only.

To workaround that you could create a Dynamic Action on the Global Page, have it fire on Page Load and execute this Javascript:

jQuery("a[href*='f?p=&APP_ID.:']").each(function(){
var vThis$ = jQuery(this);
vThis$.attr("href",vThis$.attr("href").replace("=&APP_ID.:","=&APP_ALIAS.:"));
});

I did use that a long time to guarantee to have nice Alias’s in my URLs, and it worked pretty well.

Please Note: due to a Bug in Oracle APEX (all Versions, so far up to 4.2.4.00.07) the Application Alias isn’t checked for uniqueness across all workspaces when editing the application properties. This unfortunately leads to an error when trying to run that application:  The application alias “MYALIAS” can not be converted to a unique application ID.

 That’s not good enough, can you do better?

Above mentioned methods are a start, but nowhere close to real readable URLs. What Options do we have?

Well, I turned to my good old friend, the search-machine and found some possible solutions

  • Using iframes, but we’ll immediately forget about that
    since APEX 4.1 all applications prevent to run inside a frame (unless you change the security settings)
  • Apache Rewrite Rules
    There are a couple Forum entries and some Blogposts dealing with Rewrite Rules.
    In my own experience it is very cumbersome to define those rules and you really need to understand the syntax.
  • mod_plsql and EPG PathAliasProcedure
    Morten found a very old gem with that PathAliasProcedure
  • APEX Listener Webservice
    The latest method, described by Mr. Webservice himself

The last two options caught my eye. The proposed usage in the blogpost wasn’t exactly what I wanted, so I refined that and finally came up with a very easy to use solution which works no matter if you have mod_plsql/EPG or APEX Listener.

Continue reading in the next blogpost :-)

 

 

3 thoughts on “hrURL – human readable URLs in Oracle APEX

  1. Hello Peter,
    Thanks for sharing your experience. When visiting a Home Page, is there a way to show only the domain name.
    e.g,
    myserver.com/pls/apex/hrurl/home
    shows up as:
    myserver.com

    Regards,

  2. Pingback: How we built our new website using Oracle APEX - FOEX Blog

  3. Hello Peter

    Could you please tell me how can I use session ID = 0. I tried various ways like replace_URL but my session ID is not getting set to 0 while loading.

    Would highly appreciate your help !!

    Cheers
    Amit

Leave a Reply

Your email address will not be published. Required fields are marked *