How to make UrlRewrite write absolute URLs to location header field

27 views
Skip to first unread message

Stefan Makakis

unread,
May 14, 2012, 7:05:00 AM5/14/12
to UrlRewrite
Hi there,

according to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.30
the URL in location field must be absolute.

When I define the following rule

<rule>
<from>^/search/([SEARCH_TERM_REGEX])/page-1.html$</from>
<to type="permanent-redirect">/search/$1.html</to>
</rule>

UrlRewrite writes "/search/[SEARCH_TERM_REGEX].html" to the location
header field (as described here:
http://urlrewritefilter.googlecode.com/svn/trunk/src/doc/manual/3.2/index.html
– "Configuration File WEB-INF/urlrewrite.xml" > "<to> element").

Is there an elegant way to make UrlRewrite write absolute URIs to the
location haeder field, using hostname etc. from the request?

E.g.
http://www.example.org/search/foo/page-1.html -301->
http://www.example.org/search/foo.html

instead of

http://www.example.org/search/foo/page-1.html -301-> /search/foo.html

Thanks.

Wim De Smet

unread,
May 14, 2012, 8:26:50 AM5/14/12
to urlre...@googlegroups.com
Hi,

On Mon, May 14, 2012 at 1:05 PM, Stefan Makakis
<stefan....@googlemail.com> wrote:
> Is there an elegant way to make UrlRewrite write absolute URIs to the
> location haeder field, using hostname etc. from the request?

You can fetch servername etc. using functions, values are taking from
the HttpRequest.
So you could redirect to
http://%{server-name}:%{port}/%{context-path}/... (see the docs for
specifics)

regards,
Wim

Stefan Makakis

unread,
May 14, 2012, 9:55:42 AM5/14/12
to UrlRewrite
Hi Wim,

thanks for the quick answer.

On 14 Mai, 14:26, Wim De Smet <krom...@gmail.com> wrote:
> You can fetch servername etc. using functions, values are taking from
> the HttpRequest.
> So you could redirect to
> http://%{server-name}:%{port}/%{context-path}/... (see the docs for

Hmm, yeah, I actualy know that way. I hoped there was a nicer one.
Because there are about 20 rules or so I have to repair and building
the url-part before the part I match with the from element is not
trivial and depends highly on the deployment environment.

Best regards,
s
Reply all
Reply to author
Forward
0 new messages