Making URLs prettier using URL rewriting.
URL rewriting is a completely optional feature of Wheels, and all it does is get rid of the index.cfm
part of the URL.
For example, with no URL rewriting, a URL in your application could look like this:
After turning on URL rewriting, it would look like this:
Combine this with the routing functionality of Wheels, and you get the capability of creating some really human-friendly (easier to remember, say over the phone, etc.) and search engine friendly (easier to crawl, higher PageRank, etc.) URLs.
Once you have added the rewrite rules (usually in either .htaccess
, web.config
or urlrewrite.xml
), Wheels will try and determine if your web server is capable of rewriting URLs and turn it on for you automatically. Depending on what web server you have and what folder you run Wheels from, you may need to tweak things a little though. Follow these instructions below for details on how to set up your web server and customize the rewrite rules when necessary.
Head's Up!
Since 2.x, engine specific URL rewrite files are not included in the default distribution. Don't worry - we've got you covered though!
For webserver specific instructions look at the following pages:
If you need to make changes to get URL rewriting to work, it's important to remember to always restart the web server and the ColdFusion server to make sure the changes are picked up by Wheels.
If you don't have access to restart services on your server, you can issue a reload=true
request. It's often enough.
URL rewriting instructions for Apache
First in your web.xml add the following servlet mapping above the default servlet mapping:
For this you can use the global web.xml that for instance can be found at: /opt/lucee/tomcat/conf/web.xml. Or, if you are on shared hosting, use a local web.xml that for instance can be found at: yourwebroot/WEB-INF/web.xml.
After that use the following .htaccess
file and Apache will pick up and use them automatically on server start-up.
Most of the time this will work. There are some exceptions though...
If you have installed Apache yourself you may need to turn on the rewrite module and/or change the security settings before URL rewriting will work:
Check that the Apache rewrite_module
has been loaded by ensuring there are no pound signs before the line that says LoadModule rewrite_module modules/mod_rewrite.so
in the httpd.conf
file.
Make sure that Apache has permission to load the rewrite rules from the .htaccess
file. This is done by setting AllowOverride
to All
under the Directory section corresponding to the website you plan on using Wheels on (still inside the httpd.conf
file).
If you have an older version of Apache and you're trying to run your Wheels site in a sub folder of an existing site you may need to hard code the name of this folder in your rewrite rules.
Change the last line of the .htaccess
file to the following: RewriteRule ^(.*)$ /sub_folder_name_goes_here/rewrite.cfm/$1 [L]
. Don't forget to change sub_folder_name_goes_here
to the actual folder name first of course.
Note that it's often considered better practice to include this URL rewriting configuration at the <virtualhost>
block level, but get it working with a .htaccess
file first.
URL rewriting instructions for IIS
Similar to Apache, IIS 7 will pick up the rewrite rules from a file located in the Wheels installation. In the case of IIS 7, the rules are picked up by adding the following web.config
file.
This requires that the URL Rewrite Module is installed. It's an IIS extension from Microsoft that you can download for free.
Missing Lucee Assets?
If you had an issue with missing Lucee CSS files, try changing{SCRIPT_NAME}
to{PATH_INFO}
in the code above, as this reportedly can resolve the issue.
Deprecated
Please note that IIS6 was official End of Life as of 2015. These notes are included for historical purposes only.
Unfortunately, there is no built-in URL rewriting mechanism in IIS 6, so getting Wheels working with pretty URLs is a little more complicated than with Apache and IIS 7 (which often comes with the official "URL Rewrite Module" installed by default). Here's what you need to do:
Download Ionic's ISAPI Rewrite Filter. NOTE: the version must be v1.2.16 or later.
Unzip the file, get the IsapiRewrite4.dll
file from the lib folder and put it in the root of your website. (It needs to be in the same folder as the IsapiRewrite4.ini
file.)
To enable the rewrite filter in IIS 6, click on Properties for your website, then go to the ISAPI Filters tab and click the Add... button.
Type in anything you want as the Filter Name and point the Executable to the IsapiRewrite4.dll
file.
Uncomment the rewrite rules in the IsapiRewrite4.ini
file.
NOTE: Make sure you have "Verify that file exists" disabled for your site.
Right click your website and select Properties.
Click Home Directory tab.
Click the Configuration button.
Under the Wildcard application mapping section, double-click path for the jrun_iis6_wildcard.dll
.
Uncheck Verify that file exists.
Click OK until all property screens are closed.
URL rewriting instructions for Tomcat
UrlRewriteFilter (commonly referred to as Tuckey) is a Java web filter for compliant web application servers such as Tomcat, Jetty, Resin and JBoss. Unfortunately UrlRewriteFilter depends on XML with its extremely strict syntax.
Append the servlet-mapping markup to the end of the <filter mapping>
element in your WEB-INF/web.xml
Add the pretty urls rule markup to the <urlrewrite>
element to your WEB-INF/urlrewrite.xml
configuration.
Restart the web application server.
Servlet-Mapping markup
Example markup with UrlRewriteFilter and Wheels pretty URLs for WEB-INF/web.xml
.
Pretty URLs Rule markup
A complete barebones WEB-INF/urlrewrite.xml
configuration example with pretty URLs.
Tomcat 8 can be configured using RewriteValve
. See for examples.
First follow the ().
URL Rewriting for Nginx web server.
Example Nginx configuration