I have done the following steps according to what I have read. To note
I am using Resin 3.0.12
#1) I downloaded urlrewritefilter-2.4.tar.gz, I copied it into my
appropriate web context. Making sure when I untarred the file that
urlrewrite.xml existed beneath my WEB-INF folder, and the jar in the
tar was in my lib/ directory.
#2)I added the following to my web.xml file, within web-app but above
my servlet-mappings as instructed:
<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>
#3)I added the following rule to urlrewrite.xml
<rule>
<name>Domain Name Check</name>
<condition name="host"
operator="notequal">www.mydomain.com</condition>
<from>(.*)</from>
<to type="redirect">http://www.mydomain.com/context$1</to>
</rule>
#3)I then stopped & started Resin, in my normal manner.
The website is served but I am not getting my redirects? Any
suggestions, or mistakes in the above process? Do I need to make any
adjustments to my resin.conf? It currently has an entry related to this
site as follows:
<host id='mydomain.com'>
<host-alias>www.mydomain.com</host-alias>
<web-app id='/'
document-directory="/data/local-sites/mydomain.com">
<session-config enable-cookies='false'/>
</web-app>
<access-log path='log/access.log'>
<rollover-period>2W</rollover-period>
</access-log>
</host>
after adding the above to my <filter> tag into my
/data/sites/www.mydomain.com/WEB-INF/web.xml.
I see the following lines in my debug.log.
[08:08:30.249]resin:import
'/data/sites/www.mydomain.com/WEB-INF/web.xml'
[08:08:30.261]filter-mapping /* -> UrlRewriteFilter
[08:08:30.261]filter-mapping /* -> UrlRewriteFilter
...
...
[08:08:49.599]org.tuckey.web.filters.urlrewrite.UrlRewriteFilter DEBUG:
filter init called
[08:08:49.600]org.tuckey.web.filters.urlrewrite.UrlRewriteFilter DEBUG:
calling destroy just in case we are being re-inited uncleanly
[08:08:49.600]org.tuckey.web.filters.urlrewrite.UrlRewriteFilter INFO:
destroy called
That is all I see that is different. Please let me know if you need
more of this file because I could supply the whole thing.
Here is an example of the /rewrite-status if that might help:
Running Status
Conf file urlrewrite.xml loaded Thu May 19 08:08:59 PDT 2005.
Conf file reload check disabled
Status path /rewrite-status.
Summary of urlrewrite.xml
In total there are 2 rules, 1 outbound rule and 1 condtion in the
configuration file.
Rule 0
The rule means that requests to /test/status/ will be redirected to
/rewrite-status
the url will be rewritten.
URL's matching /test/status/ will be redirected to /rewrite-status.
Domain Name Check (rule 1)
URL's matching http://mydomain.com/(.*) will be redirected to
http://www.mydomain.com/$1.
Given that the following condtion is met.
1. The host HTTP header matches the value mydomain.com
Outbound Rule 0
The outbound-rule specifies that when response.encodeURL is called
(if you are using JSTL c:url)
the url /rewrite-status will be rewritten to /test/status/.
The above rule and this outbound-rule means that end users should
never see the
url /rewrite-status only /test/status/ both in thier location bar
and in hyperlinks
in your pages.
Outbound URL's matching /rewrite-status will be rewritten to
/test/status/.
Request Debug Info
General
method: GET
context-path:
port: 80
protocol: HTTP/1.1
remote-addr: 172.16.1.135
remote-host: 172.16.1.135
requested-session-id: xdlZ-s9CWkhxWaG1isNotUnique=true
request-uri: /rewrite-status
request-url: http://mydomain.com/rewrite-status
server-name: mydomain.com
scheme: http
Request Headers
Host: mydomain.com
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.6)
Gecko/20050317 Firefox/1.0.2
Accept:
text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Cookie: JSESSIONID=xdlZ-s9CWkhxWaG1isNotUnique=true
Cookies
Cookie 0
name : JSESSIONID
value : xdlZ-s9CWkhxWaG1isNotUnique=true
path : null
domain : null
max age : -1
is secure: false
version : 0
comment : null
Time info
time: 1116515531255
year: 2005
month: 4
dayofmonth: 19
dayofweek: 5
ampm: 0
hourofday: 8
minute: 12
second: 11
Please Note two changes from my first post, first #3 should be #4, :),
and I have also changed my rule to the following:
<rule>
<name>Domain Name Check</name>
<condition name="host" operator="equal">mydomain.com</condition>
<from>http://mydomain.com/(.*)</from>
<to type="permanent-redirect">http://www.mydomain.com/$1</to>
</rule>
-Cheers
Okay- got it all loaded as Nathan has. Ive set it to run at Debug. I'm
getting the same problem - I've set this rule to run -
<rule>
<from>^/servlet/ProductLister?queryType=([a-z]+)$</from>
<to>/servlet/ProductLister/queryType/$1</to>
</rule>
<rule>
<from>^/servlet/ProductLister/queryType/([a-z]+)$</from>
<to>/servlet/ProductLister?queryType=$1</to>
</rule>
I've tried it also without includin the /servlet part. And nothing is
happening. I review the logs - and the DEBUG from the UrlRewrite tells
me
-Filter Init Called
-Calling destroy just in case we are being re-inited uncleanly
-destroy called
But I can't any of the examples to work.
Please help :)
Note the rule should really look something like:
<rule>
<name>Domain Name Check</name>
<condition name="host" operator="equal">mydomain.com</condition>
<from>^(.*)$</from>
<to type="permanent-redirect">http://www.mydomain.com/$1</to>
</rule>
Cheers,
Paul.
After changing my rule to the above. It is working for me in my test
environment. Although it is sometimes giving me an extra innocuous '/'.
To note I am using Resin 3.0.12.
Superb piece of software. Thank you Paul :)
(Let me know where to send the donation). Its not a lot by I really
appreciate someone taking the time to donate software like this.