Redirecting Coldfusion URLs to Drupal clean URLs using Apache rewrites

There are a few sites that have moved from ColdFusion to Drupal, the highest profile perhaps being However, it wasn't easy to find any documentation on how these sites redirected old URLS to the new Drupal site. We use Clean URLs on our Drupal sites, and you should too if you aren't using them. (Info on Clean URL setup is available here I'm using Apache, so we will make use of the .htaccess file that comes with our Drupal install, we can add a rule to do our rewrite. So, the goal was:

  1. Edit the .htaccess file in the Drupal root directory
  2. Navigate to below the line in the .htaccess file (currently 107) which reads # Rewrite Base /
  3. First catch a particular query to a ColdFusion page and send it to its rightful place
  4. Redirect the URL to our Drupal URL
  5. Put in a RewriteCond to catch other ColdFusion requests
  6. Redirect these requests to go drop the .cfm (So for instance if we have a node with path of 'home' and we 'home.cfm' to now redirect to it

For my particular use case, the URLs looked like: news/newsdetail.cfm?newsID=# and I wanted them to redirect to news/#
So, for example, http://localhost/news/newsdetail.cfm?newsID=1601 redirects to http://localhost/news/1601
So, first I wanted to work off the query string and redirect the news items. Then, I could do a general redirect for other .cfm files (e.g., if I had news/addnews.cfm and want to redirect it to news/addnews)

Ok, so what's the magic rewrite rule? I used the following:

# First rewrite the news use case
RewriteCond %{QUERY_STRING} ^newsID=([0-9]*)$
RewriteRule ^(.*)$ index.php?q=news/%1 [R=302]
# Rewrite other cfm URLs to remove the .cfm
RewriteRule ^(.*).cfm$ index.php?q=$1 [L,QSA]

The newsID case could be extended for many types of queries that you may have (maybe you have eventId=### or some such), so try it out with your own queries. Though, I believe there is a limit, so you don't want to add to many here. I'd love to know if there is a better way to do this, or if the above is sufficient. I am by no means an Apache expert, so I'm sure better ways are out there to do this, and would appreciate any commentary. I don't know if this is general use case enough to make a handbook page, but if one doesn't exist, it could be helpful for those trying to migrate.



Here at, we have an F5 loadbalancer in front of our production clusters (Drupal / Coldfusion), so we write iRules that do the rewriting.

That's a great idea, we have

That's a great idea, we have an F5 load balancer as well from Big IP, so it would probably be even better to stick these rules there instead of on the servers themselves. Thanks!

Add new comment

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.

Comment using an existing account (Google, Twitter, etc.)