Can reg ex be used in host name conditional?

6 views
Skip to first unread message

Nicole

unread,
Sep 27, 2009, 10:24:29 PM9/27/09
to UrlRewrite
Hi all,

It could be my server configuration, but a rule like the following
will create a never ending redirect loop.

<rule>
<condition name="host" operator="equal">example.com</condition>

<from>^/(.*)$</from>
<to type="redirect">http://www.example.com/$1</to>
</rule>

I'm attempting to redirect non-www requests to www. However, both the
www and non-www URLs will match on the host conditional above. Can
regular expressions be used in the host condition so that I could
specify no www (I actually tried this, but it didn't work - or my reg
ex sucked)? Or is there a better way to do this?

The workaround I've found is to use "notequal" and specify every other
host name I _don't_ want redirected. However, we're serving quite a
few different domains from our CMS so that list is long, and it feels
hackish.

Any suggestions?

Thanks,

--Nicole

Avlesh Singh

unread,
Sep 28, 2009, 1:17:15 AM9/28/09
to urlre...@googlegroups.com
Did you try this?
<condition name="host" operator="equal">^example.com$</condition>

Cheers
Avlesh

Nicole

unread,
Oct 8, 2009, 11:33:05 AM10/8/09
to UrlRewrite
That was exactly what I needed (and a big "duh" to myself on that
one). Thanks!

--Nicole

On Sep 27, 11:17 pm, Avlesh Singh <avl...@gmail.com> wrote:
> Did you try this?
> <condition name="host" operator="equal">^example.com$</condition>
>
> Cheers
> Avlesh
>
Reply all
Reply to author
Forward
0 new messages