Tag Archives: Apache

Servlet/Portlet Filter for Url-Rewriting

When it comes to URL rewriting the first thing that comes in mind is using the Apache config file httpd.conf. That’s generally good but has the disadvantage that your webapp cannot be installed without modifying a system file with root access, which not everyone might have. Anyway … this could look something like this:

Another nicer approach is to use this URL-RewriteFilter, which will be part of your webapp. You just need to copy the library into the lib-folder of your webapp and activate the filter in your web.xml like this:

This will filter all incoming URLs from the root, before they actually reach the webapp’s code. Check out the website for more options! If a webapp has for example the path “/my-portal/portal/default-page.psml” which points to your start page of your Jetspeed Portal, then you can access this page with “/startPage” by adding this rule to your configuration file (urlrewrite.xml) in your WEB-INF directory:

If you also want to have rewritten all your links of your website, you need to define an outbound rule. So every link within your JSP or Velocity Macro page will also point to the pretty URL. However it is important to use “response.encodeURL(…)” for all links! In other words use

for jsp-pages or

for vm-pages, otherwise they might not be send through the filter, so better mark them all :) The outbound-rule has to be defined something like this:

Posted in Apache, Java | Tagged , , | Leave a comment