Domain Redirect Question

70 views
Skip to first unread message

nathan...@gmail.com

unread,
May 18, 2005, 2:53:55 PM5/18/05
to urlre...@googlegroups.com
Hello, I am trying to use UrlRewrite to forward all requests to
http://mydomain.com onto http://www.mydomain.com.

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>

Paul Tuckey

unread,
May 18, 2005, 8:20:22 PM5/18/05
to urlre...@googlegroups.com
If you add

<!-- sets up log level (will be logged to context log)
can be: TRACE, DEBUG, INFO, WARN, ERROR, FATAL -->
<init-param>
<param-name>logLevel</param-name>
<param-value>DEBUG</param-value>
</init-param>

to your <filter> conf what do you see in the logs? If the filter being started.

Cheers,
Paul.

nathan...@gmail.com

unread,
May 19, 2005, 12:17:05 PM5/19/05
to urlre...@googlegroups.com
Hi Paul,

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

pa...@hawkhurstcomputing.co.uk

unread,
May 22, 2005, 2:08:13 PM5/22/05
to urlre...@googlegroups.com
Hi

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 :)

Paul Tuckey

unread,
May 22, 2005, 7:11:44 PM5/22/05
to urlre...@googlegroups.com
It looks like the destroy method of the filter is being called out of
sequence, can you tell me what application server and version you are
using?

Cheers,
Paul.

Paul

unread,
May 22, 2005, 7:27:38 PM5/22/05
to urlre...@googlegroups.com
Could you try setting the log level to TRACE also.

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.

nathan...@gmail.com

unread,
May 23, 2005, 11:22:54 AM5/23/05
to urlre...@googlegroups.com
Thanks 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.

Paul Tuckey

unread,
May 23, 2005, 3:46:02 PM5/23/05
to urlre...@googlegroups.com
Just change your from to be <from>^/(.*)$</from>.

Cheers,
Paul.

pa...@hawkhurstcomputing.co.uk

unread,
May 24, 2005, 5:16:36 AM5/24/05
to urlre...@googlegroups.com
All working on my side now. The only thing I changed was that I was
failing to escape a "?" symbol in one of my rules.

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.

Paul Tuckey

unread,
Jun 20, 2005, 7:47:18 PM6/20/05
to urlre...@googlegroups.com
There is a donation button on the bottom of http://tuckey.org/urlrewrite/

Any donation to help with hosting fees is much appreciated!


Thanks,
Paul.

On 24/05/05, pa...@hawkhurstcomputing.co.uk
Reply all
Reply to author
Forward
0 new messages