Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

"If" tag in <VIRTUAL_HOST> of httpd.conf file checking HTTP_UESR_AGENT of apache 2.4 not working as expected.

418 views
Skip to first unread message

Sharat Hegde

unread,
May 13, 2013, 1:45:23 AM5/13/13
to
I found out from documentation that from Apache 2.3 onwards we can use <If></If>
tag in hattpd.conf file.

But when tried following in my httpd.conf file I am not able to get required redirection.

part of httpd.conf file is as follows:

LoadModule rewrite_module modules/mod_rewrite.so

<VirtualHost *:80>

ServerName localhost:80
ServerAlias localhost1
<If "%{HTTP_USER_AGENT} == 'iphone'">
RewriteEngine on

Redirect / http://172.26.50.246:90/
</If>

DocumentRoot "C:/Apache24/htdocs"

</VirtualHost>

Please help me in finding flaw in above sniplet...
Thanks

Kees Nuyt

unread,
May 13, 2013, 4:26:22 AM5/13/13
to
Two remarks.

1) I don't think you need "RewriteEngine on" here.
Redirect is a directive of mod_alias, not mod_rewrite.
http://httpd.apache.org/docs/2.4/mod/mod_alias.html#redirect

Before Apache httpd 2.3 this case would indeed be solved with
Rewrite, <if > is a nice alternative, available in core.

2) Are you sure HTTP_USER_AGENT is exactly 'iphone'?
You may have to use -strmatch in this case.

http://httpd.apache.org/docs/2.4/expr.html#binop

(untested, I hope it helps)
--
Kees Nuyt
Message has been deleted

Sharat Hegde

unread,
May 13, 2013, 5:04:30 AM5/13/13
to
Thanks for your input Kees.

Using Rewrite rule, was able to track request from USER_AGENT 'iphone', so I tried same here.

Now I am trying with '-strmatch'....
I would be thankful to you, if you share an example using the same since I am new it.
Thank you.

Sharat Hegde

unread,
May 13, 2013, 7:58:22 AM5/13/13
to
Thanks for reply Kees.
As you suggested it can be done using "-strmatch"

I found solution which is as follows


<If "%{HTTP_USER_AGENT} -strcmatch '*iphone*'">
Redirect / http://172.26.50.246:100/
</If>



Thanks

Kees Nuyt

unread,
May 13, 2013, 9:26:09 AM5/13/13
to
That's great. I'm glad it works.

>Thanks

My pleasure. Thanks for letting us know it works.
--
Kees Nuyt
0 new messages