Clean URLs in Drupal with Apache and Tomcat

I've just returned from the land of jar -xzf. I've installed a couple of new Drupal sites (details to follow). One of those sites takes over the whole domain. The other is just a subset. I ran into trouble with the infamous "Clean URLs" feature, and only found the solution after hours of fruitless Googling.

Drupal is a PHP content management system. In PHP, the URL addresses the program, and any parameters must be supplied in the query string. Drupal URLs therefore look something like this:

There are a few things we can do to make the URL prettier. First, we can configure the web server to serve index.php by default. Most web servers are initially configured to do just that, so the URL could be written like this:

That's better, but SEO is harmed by the question mark. So we turn on mod_rewrite to change that URL to this:

A tale of two sites
This was all well and good. I followed the directions found on blogs too numerous to mention for configuring mod_rewrite. These instructions worked fine for one of my sites, but not the other.

What's the difference? On the site that worked, Drupal was installed in a subdirectory. On the site that failed, Drupal was installed in the root. The problem has something to do with the lack of a subdirectory in the URL.

In the course of troubleshooting, I tried removing the "?=q" from various URLs. It worked for content pages, but failed for admin pages. So, I reasoned, the problem is with "/admin" as the top folder.

What was most telling is what happened when I entered a URL with just "/admin". The Tomcat administration page appeared. I have Tomcat installed on my server, but I'm not using it on the full Drupal site. Drupal is PHP, not Java, and this site has no other content. So why is Tomcat showing up?

My host (eApps) defines a default configuration for any new site I create. This configuration includes Tomcat, because I typically host Java applications rather than PHP applications. The configuration includes this line in httpd.conf (located in /etc/httpd/conf):

JkMount /admin* ajp13

This directs the "/admin" URL to Tomcat through mod_jk. I just removed this line from this site's configuration, and I was able to turn on clean URLs.

Every site is different. The solutions that you find on blogs (including this one) won't necessarily work for you. It is best to hone your troubleshooting skills and attack the problem systematically than to Google for the error message. I mean, what are the odds that your environment is exactly like mine?

Leave a Reply

You must be logged in to post a comment.