URL Rewrite Plugin

  • Tags: functionality
  • Latest: 0.1
  • Last Updated: 04 February 2009
  • Grails version: *
  • Authors: Mingfai Ma
0 vote
Dependency:
compile ":urlrewrite:0.1"

 Documentation

Summary

Description

This plugin install a customized version of Tuckey's URL Rewrite Filter to the project

Important: Read this first

  • This plugin installs a customized version of URL Rewrite Filter.
    • It is based on 3.2.0 source code
    • Source code are modified to use SLF4j
    • The customization is done because the arthor of this plugin cannot figure out how to configure logging for the filter in Grails. If you know how to do, please contribute your work so we don't need to do manual processing whenever we update the library
  • The arthor use the filter to do URL Rewrite for non-Grails servlet and have never test it against Grails controller and Grails-managed URL. According to some posts on the Grails and URL Rewrite Filter mail lists, the filter doesn't work well with URL Filter.
    • For Grails user, it will take just some mins to test so i suppose there is no harm for you to create a new app, install the plugin and try it out to see if it meets your needs

Installation and Configuration

Installation

grails install-plugin urlrewrite

Configuration

  • Configure init-param of the Servlet Filter of URL Rewrite Filter
    • Sample Config.groovy, refer to the SVN Version for the latest example
      plugins{
        urlrewrite{
          filter{
            initParameters {
              statusEnabled=true
              modRewriteConf=false
              //confPath='/.htaccess'
            }
          }
        }
      }
      
  • setting servlet context
    • you are highly commended to use the root context to avoid confusion when setting URL pattern in rules.
    • for jetty or grails run-app, put a web-jetty.xml under /web-app/WEB-INF
      <?xml version="1.0"  encoding="ISO-8859-1"?> 
      <!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://jetty.mortbay.org/configure.dtd"> 
      <Configure class="org.mortbay.jetty.webapp.WebAppContext"> 
          <Set name="contextPath">/</Set> 
          <Set name="war"> 
              <SystemProperty name="jetty.home" default="."/>/webapps/yourAppName 
          </Set> 
          <Set name="VirtualHosts"> 
              <Array type="java.lang.String"> 
                  <Item>yourdomain.com</Item> 
                  <Item>localhost</Item> 
              </Array> 
          </Set> 
      </Configure> 
      
  • Use of the filter
    • refer to URL Rewrite Filter manual
    • there are several ways to configure URL Rewrite Filter. by default, it takes a web-app/WEB-INF/urlrewrite.xml, check the original example.
    • NOTICE When the urlrewrite.xml contains a DTD reference, an exception will be thrown. to workaround, remove the DOCTYPE line from your xml.
      • original
        <?xml version="1.0" encoding="utf-8"?> 
        <!DOCTYPE urlrewrite PUBLIC "-//tuckey.org//DTD UrlRewrite 3.2//EN" 
                "http://tuckey.org/res/dtds/urlrewrite3.2.dtd"> 
        
      • change to
        <?xml version="1.0" encoding="utf-8"?>
  • Logging
    • use Log4j DSL - see the Grails' official documentation
      'trace' 'org.tuckey'
    • use Log4j XML Plugin - Example:
      'log4j:configuration'("xmlns:log4j": "http://jakarta.apache.org/log4j/", debug: "false") { 
      
        appender(name: 'APP_LOG', 'class': "org.apache.log4j.DailyRollingFileAppender") {
          errorHandler 'class': "org.apache.log4j.helpers.OnlyOnceErrorHandler"
          param name: "File", value: "logs/app.log"
          param name: "Append", value: "false"
          param name: "DatePattern", value: "'.'yyyy-MM-dd"
          layout('class': "org.apache.log4j.PatternLayout") {
            param name: "ConversionPattern", value: "%d %-5p [%-30.40c] %2X{tid} %X{sid} %X{uid} %m%n"
          }
        }
      
        appender(name: "CONSOLE", 'class': "org.apache.log4j.ConsoleAppender") {
          errorHandler 'class': "org.apache.log4j.helpers.OnlyOnceErrorHandler"
          param name: "Target", value: "System.out"
          param name: "Threshold", value: "TRACE"
          layout('class': "org.apache.log4j.PatternLayout") {
            param name: "ConversionPattern", value: "%d{ABSOLUTE} %-5p [%c{1}][%X{tid}] %m%n"
          }
        }
      
        'category'(name:'org.tuckey', additivity:'false'){
          'priority'(value: 'TRACE') 
          'appender-ref'('ref': "APP_LOG") 
          'appender-ref'('ref': "CONSOLE")
        }
      }
      

Wanted

  • The author believes the Tuckey's URL Rewrite Filter has great potential to strengthen Grails' URL Mapping capability. However, his use of the filter is limited to enable URL Mapping for some Grails PHP applications. It would be beneficial to the Grails community for this plugin to get a new owner to actively develops it.
  • This plugin is looking for helper, contributor, or new owner.
Author: Mingfai Ma (mingfai.ma (at-no-spam) gmail.com)