Readable URLs for Custom Scripts
Submitted by jdeathe on Wed, 11/12/2014 - 06:27
The recommended location for custom scripts written for the Jadu CMS platform is within <install-path>/public_html/site/custom_scripts/ but this can lead to long and unfriendly URLs. Here we show how to use the Readable URLs feature to create a cleaner URL structure for a simple custom script.
Installation
1. Create a new directory <install-path>/public_html/site/custom_scripts/howto_custom_script_readable_urls and populate it with the following files:
- htaccess_readable - containing:
# custom_scripts/howto_custom_script_readable_urls
RewriteRule ^/?app_1/(.*)$ /site/custom_scripts/howto_custom_script_readable_urls/$1 [QSA,NC,L]
RewriteRule ^/?app_1/?$ /site/custom_scripts/howto_custom_script_readable_urls/index.%EXTENSION% [QSA,NC,L]
- index.php
<?php print "PHP Version: " . phpversion();
2. Add the following to the end of <install-path>/public_html/config/readable_urls.xml
<custom_scripts_howto_custom_script_readable_urls><config:constant name="MAIN_HOME_DIR" />public_html/site/custom_scripts/howto_custom_script_readable_urls/htaccess_readable</custom_scripts_howto_custom_script_readable_urls> It should end up looking something like this:
<?xml version="1.0" encoding="utf-8" ?>
<readable_urls xmlns:config="http://www.jadu.co.uk/schema/config">
<core><config:constant name="MAIN_HOME_DIR" />jadu/htaccess_readable</core>
<multimedia><config:constant name="MAIN_HOME_DIR" />jadu/multimedia/htaccess_readable</multimedia>
<publishing><config:constant name="MAIN_HOME_DIR" />jadu/websections/htaccess_readable</publishing>
<marketing><config:constant name="MAIN_HOME_DIR" />jadu/marketing/htaccess_readable</marketing>
<recruitment><config:constant name="MAIN_HOME_DIR" />jadu/recruitment/htaccess_readable</recruitment>
<egov><config:constant name="MAIN_HOME_DIR" />jadu/egov/htaccess_readable</egov>
<xforms><config:constant name="MAIN_HOME_DIR" />jadu/egov/htaccess_readable_xforms</xforms>
<utilities><config:constant name="MAIN_HOME_DIR" />jadu/utilities/htaccess_readable</utilities>
<custom_scripts_howto_custom_script_readable_urls><config:constant name="MAIN_HOME_DIR" />public_html/site/custom_scripts/howto_custom_script_readable_urls/htaccess_readable</custom_scripts_howto_custom_script_readable_urls>
</readable_urls>
3. Configuration data stored in the XML files is cached so we must remove the cache file to allow the update in step 2 to take effect. To do this from the Control Centre use the Cache Bash maintenance script - navigate to /jadu/maintenance/cacheBash.php check "Config Cache" and click "Delete Selected".
Alternatively, from the command line you can delete the cache files using:
$ sudo rm -f <install-path>/var/cache/config*4. Add and remove a temporary Readable URL via the Control Centre (/jadu/utils/friendly_urls.php) to force the .htaccess file to be rebuilt.
5. This demo script should now be accessible from http://<install-domain>/app_1 where "<install-domain>" is the domain name of your development environment for example http://jadu.local/app_1 and, if all went well you should see the version number of PHP that's installed.
General Concept:
Jadu Product:
Jadu Version:
