You have a Glassfish server.
You are a Drupal developer.
You want to run Drupal in Glassfish. More importantly, you want to have it use clean urls because without that capability, all of your urls look like this: /index.php?foo/bar/baz
. Which sucks, of course.
Let's set aside for the moment the desirability of running PHP in a Java application container for the moment1, and jump right to the meat of this geeky post. Here's how I got some of the clean url functionality you'd normally get from Apache's mod_rewrite, or using either mod_rewrite or Lua in lighttpd.
I'm assuming you've already got Glassfish installed, so from there:
jar -xvf quercus-3.2.1.war
> cd quercus-3.2.1 > wget http://urlrewritefilter.googlecode.com/files/urlrewritefilter-3.2.0-src.zip > unzip urlrewritefilter-3.2.0-src.zip
> cd ../ > wget http://ftp.drupal.org/files/projects/drupal-6.10.tar.gz > tar zxvf drupal-6.10.tar.gz Copy Drupal files to the quercus docroot > cp -r drupal-6.10/* quercus-3.2.1/
.htaccess
file, which sets up the mod_rewrite rules for Apache:# Rewrite current-style URLs of the form 'index.php?q=x'. RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
<filter> <filter-name>UrlRewriteFilter</filter-name> <filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class> </filter> <filter-mapping> <filter-name>UrlRewriteFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
<servlet></servlet>
section.
Next, create WEB-INF/urlrewrite.xml
:
<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE urlrewrite PUBLIC "-//tuckey.org//DTD UrlRewrite 2.6//EN" "http://tuckey.org/res/dtds/urlrewrite2.6.dtd"> <urlrewrite> <rule> <note> Prevent rewriting of specific files. Definitely not the best way to do this. </note> <from>^/(.*)(css|js|png|jpg|gif)$</from> <to>/$1$2</to> </rule> <rule> <note> Prevent rewriting of files in the files directory </note> <from>^/(.*)/files/(.*)$</from> <to>/$1/files/$2</to> </rule> <rule> <note> Do the Drupaly stuff </note> <from>^/(.*)$</from> <to>/index.php?q=$1</to> </rule> </urlrewrite>
>jar -cvf quercus-3.2.1.war quercus-3.2.1/*
mysqlpool
.
Set Datasource Classname to com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource
.
Plug in the following Additional Parameters for your Drupal DB:
password user databaseName portNumber serverName
That should be about it.
2: I expect that most Drupal developers aren't using IDEs like Eclipse or NetBeans, so I'm just using command-line tools here.
Comments
Todd (not verified)
Tue, 04/07/2009 - 11:41pm
Permalink
This rewrite is inadequate.
This rewrite is inadequate. I've been getting incredibly frustrated finding a way to make clean URLs work with Drupal on Quercus for this reason.
Specifically URLs like:
fail miserably. There has to be a better way to emulate mod_rewrite in a servlet container. I just can't find it for the life of me. I tried updating the regex for the latter case to:
This looks too ugly to be very right though. I'm no reg-expert.
I'm almost to the point of getting a separate hosting account just to use Apache for this and proxy calls to my Java host. That not only sounds terribly annoying, but probably won't help with .htaccess rules like:
as these require access to the file system.
Has anyone found a better way?
Christian
Wed, 04/08/2009 - 10:04am
Permalink
Yeah, I've found after
Yeah, I've found after playing with Quercus a bit more that it's not quite ready for production, perhaps maybe for very specific use cases.
For example, it doesn't support LDAP and some classess in SPL, which make it unusable for my applications.
I've also found it to be not quite as fast as the lighttpd+APC combo we run in production. At this point, I'd probably only use it for things that were heavily integrated with java code.
DD (not verified)
Thu, 08/05/2010 - 9:41am
Permalink
I am posting this quite
I am posting this quite late.. But still it may be of use to someone .
Well i was trying to deploy my drupal site on glassfish and faced with the clean url problem. This post really helped me. But as Todd, in the above post, has mentioned we need to mention these conditions
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
So this is wat i have done
- Removed the previous 2 rules
- Replaced the 3rd rule with
Do the Drupaly stuff
^/(.*)/files/(.*)$
^/(.*)(css|js|png|jpg|gif)$
^/(.*)$
/index.php?q=$1
It works great !!
DD (not verified)
Thu, 08/05/2010 - 9:49am
Permalink
Eww... Sorry for the above
Eww... Sorry for the above post.. The tags just disappeared...
Replace the 3rd rule with:
<rule>
<note>
Do the Drupaly stuff
</note>
<condition type="request-uri" operator="notequal">^/(.*)/files/(.*)$</condition>
<condition type="request-uri" operator="notequal">^/(.*)(css|js|png|jpg|gif)$</condition>
<from>^/(.*)$</from>
<to>/index.php?q=$1</to>
</rule>
Andrea Gariboldi (not verified)
Wed, 04/27/2011 - 6:49am
Permalink
a simple clean url standard
a simple clean url standard servlet filter:
then just map it in your web.xml:
Christian
Thu, 04/28/2011 - 9:02pm
Permalink
Thanks Andrea! I'll have to
Thanks Andrea! I'll have to give that a try.