06 June 2019

Setting HTTP Response Status Code 301 (Moved Permanently) in APEX

This will be a short one.  As our public-facing applications age and new applications are developed to replace them, we often have the problem that search engines still send people to the old application pages.

One way of solving this issue, and of giving some feedback to the search engines so that they will update their indexes, is by using the HTTP Response Status Code 301 "Moved Permanently".  Any self-respecting search engine that receives this response code will remove the outdated link from their index.  Also, any users that click on the old link will be automatically redirected to the new one.

Let's take an example: suppose that I have an old APEX application (e.g. app ID 88203) and I want to redirect people to the Universal Theme application (App ID 42) instead of my old page.

The only thing that I need to do is to add a "Before Header" PL/SQL process.  Let's call this process "Permanent Redirect".

This process does three things:
  1. it sets the http status to 301
  2. it redirects to the new url
  3. then it immediately halts all APEX execution by stopping the apex engine

Here's the PL/SQL code for the process:
owa_util.status_line(301,'',false); 
owa_util.REDIRECT_URL('https://apex.oracle.com/pls/apex/f?p=42:100', true);
apex_application.stop_apex_engine();


Before Header process to be created - Permanent Redirect

The Permanent Redirect process definition




One online tool that I found useful while testing this approach was https://httpstatus.io/, it's an online tool to easily check status code, response headers and redirect chains.

I hope that this comes in useful to you one of these days.  It's a quick and relatively simple approach to solving a common problem.

No comments:

Post a Comment