The recommended location for custom scripts written for the Jadu CMS platform is within /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.
- Create a new directory
<install-path>/public_html/site/custom_scripts/php_version
and populate it with the following files:
- htaccess_readable
# custom_scripts/php_version
RewriteRule ^/?custom_app/(.*)$ /site/custom_scripts/php_version/$1 [QSA,NC,L]
RewriteRule ^/?custom_app/?$ /site/custom_scripts/php_version/index.%EXTENSION% [QSA,NC,L]
- index.php
<?php
print "PHP Version: " . phpversion();
- Add the following element to
<install-path>/config/readable_urls.xml
<custom_scripts_php_version><config:constant name="MAIN_HOME_DIR" />public_html/site/custom_scripts/php_version/htaccess_readable</custom_scripts_php_version>
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>
<custom_scripts_php_version><config:constant name="MAIN_HOME_DIR" />public_html/site/custom_scripts/php_version/htaccess_readable</custom_scripts_php_version>
</readable_urls>
-
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". -
Toggle the Readable URL feature to force the .htaccess file to be rebuilt.
-
This demo script should now be accessible from
http://<install-domain>/custom_app
where<install-domain>
is the domain name of your development environment for example http://jadu-cms.local/custom_app and, if all went well you should see the version number of PHP that's installed.