Accessing Mura URL Variables

With Mura's SES URL manipulation it can be hard to access URL variables for processing. E.g., what would Mura do with www.mysite.org/index.cfm?ID1=blah&ID2=moreblah?

I find myself in this position because links like these are hardcoded in older software in possession of customers unavailable for me to change. These links need to be maintained, but creating 404s for the multitude of variables that get passed back is unreasonable.

Mura accepts URL variables with the "params" URL keyword followed by key/value pairs, or custom parameters. It's explained here: http://docs.getmura.com/developer-guides/back-end-development/url-structure-in-mura-cms

So our URL www.mysite.org/index.cfm?ID1=blah&ID2=moreblah would have to look like www.mysite.org/index.cfm/params/ID1/blah/ID2/moreblah. I did this with the Tuckey URL Rewrite Filter on Tomcat. Full details on this accomplishment will come later. For now, we'll just assume that we have successfully converted our URL variables to custom parameters.

The whole point of this article is to access the URL variables. If you've done any experimenting, you'll find that anything referencing URL throws an error (well, I did anyway).

So if your index.cfm above had this cfdump – error!

view plain print about
1<cfdump var="#URL#" />

But using the custom parameters method, your URL variables in key/value pairs are stored in the request scope! cfdumping the entire request scope will pull up a lot of stuff, but here's that for which we are looking.

view plain print about
1<cfdump var="#request.ID1#" />
2<cfdump var="#request.ID2#" />

Gives us "blah" and "moreblah", respectively.

You can also find these in the Mura scope with $.event('variableName')

So cfdumping the below, returns the same results!

view plain print about
1<cfdump var="#$.event('ID1')#" />
2<cfdump var="#$.event('ID2')#" />

Returns "blah" and "moreblah"!

So look in the request scope to access you URL variables or in the mura scope, once they are set as custom parameters in the URL.

SES URLs with Mura, Railo, Tomcat, Ubuntu

SES URLs with Mura, Railo, Tomcat, Ubuntu

It can't be done without URL Rewrite Filter from http://www.tuckey.org/urlrewrite/ .

Though I could easily wget the zip file to my Ubuntu server, Unzip is not installed, therefore, and I was unsuccessful trying to gunzip or gzip –d the zip file. I didn't want to get started downloading every little thing available whenever it was needed so I chose to download to my PC and FTP to a directory my FTP account could access. I chose the binaries zip file from http://www.tuckey.org/urlrewrite/ , unzipped into my PC, and FTP'ed up to the server.

Once on the server move the lib to my tomcat/lib directory

view plain print about
1admin@railo:/opt/railo/tomcat$ sudo mv webapps/ROOT/mysite.com/mysite/assets/urlrewrite-3.2.0.jar lib/
2admin@railo:/opt/railo/tomcat$ ls -la lib/
3total 5224
4drwxr-xr-x 2 railo railo 4096 2011-01-26 14:20 .
5drwxr-xr-x 9 railo railo 4096 2011-01-04 12:14 ..
6-rw-r--r-- 1 railo railo 15240 2010-12-17 16:37 annotations-api.jar
7-rw-r--r-- 1 railo railo 53752 2010-12-17 16:37 catalina-ant.jar
8-rw-r--r-- 1 railo railo 129627 2010-12-17 16:37 catalina-ha.jar
9-rw-r--r-- 1 railo railo 1191060 2010-12-17 16:37 catalina.jar
10-rw-r--r-- 1 railo railo 235004 2010-12-17 16:37 catalina-tribes.jar
11-rw-r--r-- 1 railo railo 32384 2010-12-17 16:37 el-api.jar
12-rw-r--r-- 1 railo railo 108570 2010-12-17 16:37 jasper-el.jar
13-rw-r--r-- 1 railo railo 525001 2010-12-17 16:37 jasper.jar
14-rw-r--r-- 1 railo railo 1407902 2010-12-17 16:37 jasper-jdt.jar
15-rw-r--r-- 1 railo railo 76693 2010-12-17 16:37 jsp-api.jar
16-rw-r--r-- 1 railo railo 88224 2010-12-17 16:37 servlet-api.jar
17-rw-r--r-- 1 railo railo 758137 2010-12-17 16:37 tomcat-coyote.jar
18-rw-r--r-- 1 railo railo 249650 2010-12-17 16:37 tomcat-dbcp.jar
19-rw-r--r-- 1 railo railo 70035 2010-12-17 16:37 tomcat-i18n-es.jar
20-rw-r--r-- 1 railo railo 51966 2010-12-17 16:37 tomcat-i18n-fr.jar
21-rw-r--r-- 1 railo railo 55037 2010-12-17 16:37 tomcat-i18n-ja.jar
22-rw-r--r-- 1 admin admin 198436 2011-01-26 14:17 urlrewrite-3.2.0.jar

Then change group and ownership to railo:

view plain print about
1admin@railo:/opt/railo/tomcat$ sudo chown railo.railo lib/urlrewrite-3.2.0.jar
2admin@railo:/opt/railo/tomcat$ ls -la lib/
3total 5224
4drwxr-xr-x 2 railo railo 4096 2011-01-26 14:20 .
5drwxr-xr-x 9 railo railo 4096 2011-01-04 12:14 ..
6-rw-r--r-- 1 railo railo 15240 2010-12-17 16:37 annotations-api.jar
7-rw-r--r-- 1 railo railo 53752 2010-12-17 16:37 catalina-ant.jar
8-rw-r--r-- 1 railo railo 129627 2010-12-17 16:37 catalina-ha.jar
9-rw-r--r-- 1 railo railo 1191060 2010-12-17 16:37 catalina.jar
10-rw-r--r-- 1 railo railo 235004 2010-12-17 16:37 catalina-tribes.jar
11-rw-r--r-- 1 railo railo 32384 2010-12-17 16:37 el-api.jar
12-rw-r--r-- 1 railo railo 108570 2010-12-17 16:37 jasper-el.jar
13-rw-r--r-- 1 railo railo 525001 2010-12-17 16:37 jasper.jar
14-rw-r--r-- 1 railo railo 1407902 2010-12-17 16:37 jasper-jdt.jar
15-rw-r--r-- 1 railo railo 76693 2010-12-17 16:37 jsp-api.jar
16-rw-r--r-- 1 railo railo 88224 2010-12-17 16:37 servlet-api.jar
17-rw-r--r-- 1 railo railo 758137 2010-12-17 16:37 tomcat-coyote.jar
18-rw-r--r-- 1 railo railo 249650 2010-12-17 16:37 tomcat-dbcp.jar
19-rw-r--r-- 1 railo railo 70035 2010-12-17 16:37 tomcat-i18n-es.jar
20-rw-r--r-- 1 railo railo 51966 2010-12-17 16:37 tomcat-i18n-fr.jar
21-rw-r--r-- 1 railo railo 55037 2010-12-17 16:37 tomcat-i18n-ja.jar
22-rw-r--r-- 1 railo railo 198436 2011-01-26 14:17 urlrewrite-3.2.0.jar

Now move the ulrewrite.xml to the appropriate WEB-INF directory:

view plain print about
1admin@railo:/opt/railo/tomcat$ sudo mv webapps/ROOT/mysite.com/mysite/assets/urlrewrite.xml webapps/ROOT/WEB-INF/

Don't forget to change ownership:

view plain print about
1admin@railo:/opt/railo/tomcat$ sudo chown railo.railo webapps/ROOT/WEB-INF/urlrewrite.xml

Now you can follow these very clear instructions from Adam Presley and Steve Good.

http://blog.adampresley.com/2010/ses-urls-with-mura-on-tomcat/
http://stevegood.org/blog/rewriting-urls-with-railo-resin-for-mura-cms/

But there are some differences....

My /opt/railo/tomcat/webapps/ROOT/WEB-INF/web.xml contained only:

view plain print about
1<web-app xmlns="http://java.sun.com/xml/ns/javaee"
2 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
4 version="2.5">

5
6 <display-name>Welcome to Tomcat</display-name>
7 <description>
8 Welcome to Tomcat
9 </description>
10</web-app>

So I added this right after the <description> tag

view plain print about
1<!-- URL Rewrite Filter -->
2 <filter>
3 <filter-name>UrlRewriteFilter</filter-name>
4 <filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
5 <init-param>
6 <param-name>logLevel</param-name>
7 <param-value>WARN</param-value>
8 </init-param>
9 </filter>
10 <filter-mapping>
11 <filter-name>UrlRewriteFilter</filter-name>
12 <servlet-name>CFMLServlet</servlet-name>
13 </filter-mapping>
14
15 <!-- SES URL pattern -->
16 <servlet-mapping>
17 <servlet-name>CFMLServlet</servlet-name>
18 <url-pattern>/index.cfm/*</url-pattern>
19 </servlet-mapping>

There is a /opt/railo/tomcat/conf/web.xml which contains all the mappings and all the other servlet-mappings.

In urlrewrite.xml in the same /WEB-INF/ folder this was added under the /test/status/ rule

view plain print about
1<rule>
2        <note>
3            Makes all requests forward to /index.cfm/whatever-came-next
4            Ignores admin URLs so the admin still works correctly for Mura.
5        </note>
6        <from>^/(?!admin|plugins|js|css|assets|images|tasks|railo-context|flex2gateway|wysiwyg)(.*)$</from>
7        <to>/index.cfm/$1</to>
8    </rule>

SES URLs With Mura on Tomcat

I did not write this blog post. I copied directly from Adam Presley's Blog. I copied this purely for convenience and ease of multiple reference within this site. Thank you Adam!

and so Adam says...

Tonight as I'm setting up a new server I wanted to make sure I had URL rewrite ability. Normally this is no issue as I use Apache for most anything web server related. However this time I am setting up a Mura site on Railo running on Tomcat. And yes, I'm using Tomcat for both my Java Servlet engine and my web server. As such I wanted to ensure I have "pretty URLs" for my Mura-based application. In this post I will attempt to show you how to set that up.

At this point I am going to assume you have a running Tomcat and Mura application. The first thing we need to do is download Paul Tuckey's excellent UrlRewriteFilter Java filter. This can be located at http://www.tuckey.org/urlrewrite/. The version I downloaded as of this writing is 3.2.0. Once downloaded you can extract the contents anywhere you wish to keep it. You will notice there isn't much there... in fact at the top level there is only a folder named WEB-INF. Opening that folder doesn't reveal much more.

If you have Tomcat running you'll need to stop it temporarily for this next part. After stopping Tomcat, copy the file /WEB-INF/lib/urlrewrite-3.2.0.jar into your lib folder, found at {TOMCAT}/lib, where {TOMCAT} is the folder where you have placed your Tomcat installation. By copying this JAR file there you are making the URL re-writer filter available to all Java applications running in your Tomcat instance.

The next phase is to setup Railo (yes, you can do this in Adobe CF as well) to use this Java re-writer filter. Where you do this varies based on how you have setup your Railo application, but I have my Railo files extracted in my Mura application's web root directory. So in my main Mura directory I have a WEB-INF folder containing the entire Railo library.

If you open up that WEB-INF folder there should be a web.xml file. Open this file in your favorite text editor. Near the top, after the <display-name> node and before the <servlet> nodes paste the following XML.

view plain print about
1<!-- URL Rewrite Filter -->
2    <filter>
3        <filter-name>UrlRewriteFilter</filter-name>
4        <filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
5        <init-param>
6             <param-name>logLevel</param-name>
7             <param-value>WARN</param-value>
8        </init-param>
9    </filter>
10    <filter-mapping>
11        <filter-name>UrlRewriteFilter</filter-name>
12        <servlet-name>CFMLServlet</servlet-name>
13    </filter-mapping>

This block of XML tells Tomcat, when loading your application, to install this URL re-write filter, and to map any requests that come through the CFMLServlet to it. Basically that means that any CFM or CFC requests will go through the filter.

The next part of this same file that must be altered is the servlet mappings to allow paths after "index.cfm". This allows Mura to execute requests like "/index.cfm/contact-us/". To do this find the following block of XML:

view plain print about
1<servlet-mapping>
2        <servlet-name>CFMLServlet</servlet-name>
3        <url-pattern>*.cfm</url-pattern>
4    </servlet-mapping>

Once you find this, you want to insert this next block of XML right after it.

view plain print about
1<servlet-mapping>
2        <servlet-name>CFMLServlet</servlet-name>
3        <url-pattern>/index.cfm/*</url-pattern>
4    </servlet-mapping>

Now we are ready to configure the re-writer filter to forward our "pretty" SES URLs to index.cfm! In the extracted files there is a file named urlrewrite.xml. Copy this file into the same folder as your Railo web.xml file that we just got done modifying. Now open it up. Fortunately this file is pretty well documented, and the online docs have even more information! For the moment, though, we just want to make sure that all of our SES URLs go to the right place. The other concern here is to also ensure that when we go to Mura's administrator, the URLs DO NOT get forwarded to index.cfm. So, with a little bit of regular expression magic, we can make UrlRewriteFilter do this.

view plain print about
1<?xml version="1.0" encoding="utf-8"?>
2<!DOCTYPE urlrewrite PUBLIC "-//tuckey.org//DTD UrlRewrite 3.2//EN" "http://tuckey.org/res/dtds/urlrewrite3.2.dtd">
3
4<!--
5
6 Configuration file for UrlRewriteFilter
7 http://tuckey.org/urlrewrite/
8
9-->

10<urlrewrite>
11    <rule>
12        <note>
13            Makes all requests forward to /index.cfm/whatever-came-next
14            Ignores admin URLs so the admin still works correctly for Mura.
15        </note>
16        <from>^/(?!admin|plugins|js|css|assets|images|tasks|railo-context|flex2gateway|wysiwyg)(.*)$</from>
17        <to>/index.cfm/$1</to>
18    </rule>
19</urlrewrite>

Ok, super. The final phase is to tell Mura that we wish to make our URL's pretty! To do this, start Tomcat back up, then log into your Mura administrator and browse to File Manager -> Application Root and click on the folder config. In this folder there is a file named settings.ini.cfm. Click on the pencil icon to the right of the file name to edit it. Once inside we are looking for two settings: siteidinurls and indexfileinurls. These settings should both be set to zero (0). Once you save those changes make sure to click on Reload Application.

And with that you should be able to browse to your Mura site without the crazy question marks or index.cfm in the URL. But if you are in the administrator you should still have all the question marks so it behaves as expected.

I hope this helped somebody out there. Cheers, and happy coding!

SES URLrewrite Filter to Hide index.cfm

So you need to hide index.cfm from the browser for pretty SES URLs for sites on Railo/Tomcat/Ubuntu and no Apache.

First, you will need the Url Rewrite Filter (http://tuckey.org/urlrewrite/).

See the related entry to see how to install and configure.

Modify your urlrewrite.xml to include:

view plain print about
1<urlrewrite>
2 <rule>
3 <note>
4 Enable TomCat to have SES links.
5 </note>
6 <condition type="request-uri" operator="notequal">\.(bmp|gif|jpe?g|png|css|js|txt|pdf|doc|xls|xml|cfc|ico)$</condition>
7 <from>^/(?!cdn|src|railo-context)(.*)$</from>
8 <to>/index.cfm/$1</to>
9 </rule>
10</urlrewrite>

Restart Railo/Tomcat

view plain print about
1sudo service railo_ctrl restart

Now you should see directory paths in your URL without the preceding index.cm.

Reference:
http://groups.google.com/group/railo/browse_thread/thread/fe19d30f1cccff7d?pli=1
http://aarongreenlee.com/share/url-rewrite-tomcat/

Hide, block and secure railo-context from your Railo Tomcat, JBoss, Resin servers

In this example I will show you how to quickly and dynamically lock down your server to block access to the Railo administration features that are enabled by default. This modification will require an additional download and the restarting of each Railo web server you wish to protect.

We will require the popular Url Rewrite Filter (http://tuckey.org/urlrewrite/).

view plain print about
1cd ~
2wget http://tuckey.org/urlrewrite/dist/urlrewritefilter-2.6.zip
3unzip -x urlrewritefilter-2.6.zip -d urlrewrite
4cd urlrewrite/WEB-INF
5ls

Now you should see listed a lib directory and the file urlwrite.xml. Both these need to be copied into your website's root /WEB-INF directory.

view plain print about
1cp -r * /var/www/mysite.com/WEB-INF
2cd /var/www/mysite.com/WEB-INF
3nano web.xml

Copy and insert this code below into your web.xml. It will tell your server to load the Url Rewrite Filter and to recheck your urlwrite.xml every 60 seconds for changes. This is important in case in the future you need to re-enable the Railo administration without the requirement of restarting your server.

view plain print about
1<?xml version="1.0" encoding="ISO-8859-1"?>
2<web-app xmlns="http://java.sun.com/xml/ns/javaee"
3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
5 version="2.5">

6
7 <!-- URL ReWriter -->
8
9 <filter>
10
11 <filter-name>UrlRewriteFilter</filter-name>
12
13 <filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
14
15 <!-- set the amount of seconds the conf file will be checked for reload
16
17 can be a valid integer (0 denotes check every time,
18
19 empty/not set denotes no reload check) -->

20
21 <init-param>
22
23 <param-name>confReloadCheckInterval</param-name>
24
25 <param-value>60</param-value>
26
27 </init-param>
28
29 <!-- you can disable status page if desired
30
31 can be: true, false (default true) -->

32
33 <init-param>
34
35 <param-name>statusEnabled</param-name>
36
37 <param-value>false</param-value>
38
39 </init-param>
40
41 </filter>
42
43 <filter-mapping>
44
45 <filter-name>UrlRewriteFilter</filter-name>
46
47 <url-pattern>/*</url-pattern>
48
49 </filter-mapping>
50
51</web-app>

Now edit your urlwrite.xml to look something like this.

view plain print about
1<?xml version="1.0" encoding="utf-8"?>
2
3<!DOCTYPE urlrewrite PUBLIC "-//tuckey.org//DTD UrlRewrite 2.6//EN"
4
5 "http://tuckey.org/res/dtds/urlrewrite2.6.dtd">

6
7<!--
8
9 Configuration file for UrlRewriteFilter
10
11 http://tuckey.org/urlrewrite/
12
13-->

14
15<urlrewrite>
16
17<rule enabled="true">
18
19    <name>Disable Railo</name>
20
21    <from>^/railo-context/admin/(.*)$</from>
22
23    <to>null</to>
24
25    <set type="status">403</set>
26</rule>
27
28</urlrewrite>

You can now restart your server and then try to access http://www.mysite.com/railo-context/admin/web.cfm or http://www.mysite.com/railo-context/admin/server.cfm. Hopefully if all went well both pages will return a HTTP status 403. If you need to re-enable these pages, edit your urlwrite.xml and change the rule enabled attribute value to false.

Credit where credit is due. This entry was copied in its entirety from http://ipggi.wordpress.com/2010/05/27/hide-block-and-secure-railo-context-from-your-railo-tomcat-jboss-resin-servers/

BlogCFC was created by Raymond Camden. This blog is running version 5.9.7. Contact Blog Owner