Creating a website in APEX might be an easy tasks for an experienced developer, but what about making your website “Google-friendly”? Or any other “Search-engine-friendly”? By default, APEX applications have very little “out-of-the-box” features for Search Engine Optimization (SEO). The URL links look messy, you have no default description or keywords meta-tag. But all this can be fixed by following these simple rules. These rules were enforced on the old versio of www.apexninjas.com (built on APEX NinjaBlog Platform) and have proven to work (over 50% of our daily hits come from Google) and are basically simple SEO guidelines:
1. Make sure each of your site pages has a distinct name. Do not look at an APEX page (which is an application page) as a webpage. They might be same, but might also not.
2. Insert “description” and “keywords” meta tags in each of your pages’ HTML header
3. Create a sitemap and register it to Google Webmaster Tools application. Eliminate the session id from the URLs.
4. Follow basic SEO rules: content is king, use H1 and H2 tags for titles, use bold text for emphasis, add alt tags to your pictures and do not repeat or copy content from other web resources.
1. Give names to your website pages
This might seem like a trivial task, but most of the APEX websites reside inside a single APEX page. In some cases, like the ApexNinjas.com blog, this cannot be otherwise, as each web page is created dynamically from an administration area and some areas (like the header, menu and right panel) never change. We just submit an article id (an item) to the APEX page and dynamic content is loaded from the database in the central area. So, we have a single APEX page that loads multiple web page with different URLs. How to dynamically change the name of your page, in an article here: Change the page title based on an application item.
2. Add meta tags in the HTML header
For SEO optimization, search engines also use the Description and Keywords meta tags, that must placed in HTML header of you APEX page. Also this tags might be generated dynamically:
Edit Page, goto HTML Header and Body Attribute (APEX 4.x versions) and paste the following code:
<meta name=”Description” content=”&DESCRIPTION.”>
<meta name=”keywords” content=”&KEYWORDS.”>
Now, create the DESCRIPTION and KEYWORDS application or page items. Our choice was to create application items, since we ApexNinjas.com is made up entirely of one page and we didn’t want to overcrowd this page with too many items.
Create application (or page) processes to load values into these items:
Go to Shared Components -> Application Processes, [Create]
Create the processes as “Onload: Before Header” and set the values to DESCRIPTION and KEYWORDS items as you might find fit. For example, this is how we set up the KEYWORDS item value (Every article entry in the V_BLOG_ARTICLE view has a KEYWORDS column. This field is updated in Article section of our administration page):
if :P1_ARTICLE is not null then select KEYWORDS into :KEYWORDS from V_BLOG_ARTICLE where ARTICLE_ID = :P1_ARTICLE; else :KEYWORDS := 'apexninjas,apex,oracle,plsql,oracle application express, oracle apex, blog, tutorial, apexninjas.com, apex ninjas, oracle xe, apex help'; end if;
After creating adding the code to the APEX page header section, creating the items and the processes, the web page’s source should contain the tags, like in this example:
<meta name="Description" content="More on PDF Printing and XSL-FO layouts | ApexNinjas.com"> <meta name="keywords" content="apex, application express, pdf printing, pdf, apex ninjas, pdf printing in apex, oracle, apex ninjas, apexninjas.com">
3. Create a sitemap and submit it to Google
Creating a sitemap is proably the most important SEO tool you might use for your APEX website. One of the reasons APEX websites are are so poorly indexed by Google is because of the Session ID present in the URL:
Every time Google crawls your website it finds the the same page with a different URL, because the session id is always different. So Google might index the same page thousands of times because of this. And, as page with old session ids tend to “disappear”, Google record that pages from your site are no longer available, will create statistics with all the crawl errors and give your website poor ranking.
So you must create a sitemap where every URL from your site is stripped from the Session_ID.
The general sitemap structure is described below and is basically an XML file with an url, a location, the last modification time, the change frequency and the priority:
<?xml version="1.0" encoding="UTF-8"?> <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"> <url> <loc>http://localhost:8081/apex/</loc> <lastmod>2011-04-07</lastmod> <changefreq>hourly</changefreq> <priority>1.0</priority> </url> <url> <loc>http://localhost:8081/apex/f?p=100:1:0::::P1_ARTICLE:1878</loc> <lastmod>2011-03-24</lastmod> <changefreq>daily</changefreq> <priority>0.7</priority> </url> </urlset>
To create a sitemap for your APEX application, you must create a procedure called sitemap in your schema that, using the HTP Oracle package, returns HTML code representing the sitemap XML. A guide on how to create a procedure like this, here: Creating a RSS feed for your APEX application. The sitemap procedure might look like this:
create or replace procedure sitemap is v_xml blob; BEGIN WITH a AS( SELECT ba.ARTICLE_ID, ba.DAD_BASE, ba.DATE_LED from V_BLOG_ARTICLE ba ) SELECT XMLElement("urlset", XMLAttributes('http://www.sitemaps.org/schemas/sitemap/0.9' as "xmlns", 'http://www.w3.org/2001/XMLSchema-instance' as "xmlns:xsi", 'http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd' as "xsi:schemaLocation" ), ( XMLAgg( XMLElement("url", XMLElement("loc", a.DAD_BASE||'f?p=100:1:0::::P1_ARTICLE:'||a.ARTICLE_ID), XMLElement("lastmod", a.DATE_LED ), XMLElement("changefreq",'daily'), XMLElement("priority", '1.0','0.7') ) ).getblobval(nls_charset_id('AL32UTF8')) into v_xml from a; owa_util.mime_header('text/xml'); wpg_docload.download_file(v_xml); dbms_lob.freetemporary(v_xml); end sitemap;
Follow the same steps as in the RSS article mentioned above to publish this procedure. Our sitemap looks like this: http://localhost:8081/apex/sitemap
Submit the sitemap to Google
Using a Gmail account, create an Account on Google Webmaster Tools and add your website (you will have to either copy a Google control file to your servers’s root, either to add a tag in your application’s header)
Submit your sitemap here. You only have to do this once. After that, Google will periodically download your sitemap to register all changes. Your sitemap URL should be the link to your previously created procedure called sitemap, like this: http://www.yoursite/dad_base/sitemap
Also, in the Webmaster Tools panel, you can track how many URLs from your site were added to the Google directory, crawl errors, links to your site, searched keywords an so on.
4. Follow basic SEO rules
The internet is full of resources regarding SEO. Much of them are outdated (as Google changes it’s strategy often, behind the scenes), some are quite useful. The ones that must be taken in account seriously are:
– verify the robots.txt file, so that Google can access your resources and crawl your website
– use H1 and H2 HTML tags for titles and subtitles
– bold your text, for text excerpts that might need special attention from Google
– add the alternative ALT tag to your images
– keep your content original!