Rewrite header. How insert space to replacement-string

Topics: Developer Forum, User Forum
May 20, 2011 at 4:50 PM
Edited May 20, 2011 at 4:50 PM


I try to rewrite header like this:

RewriteHeader User-Agent: .* Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)

But it's not working, because spaces are used. So, how can I insert space to header string?


May 22, 2011 at 7:48 PM

hmm I don't know - have you tried using the url-encoded form?  like replacing spaces with %20?


May 23, 2011 at 8:45 AM


Yes, I tried to use %20, +, and ", but it's not helped.
Additionally, I played with UrlDecoding parameter, but result the same.


Aug 7, 2014 at 9:18 PM
Hi Thor,

Did you ever find a way to do this? I just ran into the same problem.

Thank you.
Oct 7, 2014 at 6:43 AM
I don't suppose anyone has had any luck with this. I've tried all sorts of combinations of escape characters, but can't seem to find anything that works.
Dec 13, 2016 at 11:20 AM
Finally I found a way:

I rewrote the IE11 header to an IE7 header by using this rule:
RewriteHeader User-Agent: ^.*(\s).*(7).*$ Mozilla/4.0$1(compatible;$1MSIE$1$2.0;$1Windows$1NT$16.1;$1WOW64;$1Trident/7.0;$1SLCC2;$1Media$1Center$1PC$16.0;$1.NET4.0C;$1.NET4.0E;$1GWX:RED) [L]
Basically it works like this: Most headers have a space in the string so I match the space as separate part: (\s) that I can reference with $1

In the replacement I could not differ between $1 + "7" and $17 as back reference so needed to use the "7" as back reference as well.

Hope this helps someone :-)

Hilmar Bunjes