How to redirect Query Strings with ISAPI Rewrite? -


i'm using following lines in httpd.ini file redirect users access example.com www.example.com:

rewritecond host: (?:www\.)?example.com rewriterule (.*) http\://www.example.com [rp,l] 

i'd know how redirect query strings whether user access site without www, example:

my user access:

example.com?a=1&b=2 example.com/a/b 

i'd redirect to:

www.example.com?a=1&b=2 www.example.com/a/b 

someone can me, please?

thanks lot.

this looks you're using isapi_rewrite v2, i'll answer version. v3 syntax different.

in first line, think needs ! negative lookahead www. shown, it's matching www instead of not-www.

the answer involves capturing pieces of url, using them in rewrite submatch $1, $2, etc.

rewritecond host: (?!www\.)example.com rewriterule (.*) http\://www.example.com$1 [i,rp] 


can make more generic domain, copy other websites, capturing instead of example.com. becomes first capture $1, while rest of url $2.

rewritecond host: (?!www\.)(.*) rewriterule (.*) http\://www.$1$2 [i,rp] 


rule above redirect http, if page https. if want keep http or https, as-is, e.g., https://example.com/a?b=1 https://www.example.com/a?b=1, https flag, , substitute "s". tricky describe in words: looks https server variable value 'on', , keeps if it's 'on' (this 2nd capture), , doesn't keep if it's else. then, in rule, ?2 testing if there second capture. if so, adds 's', otherwise (the colon), adds nothing (nothing after colon). in set, rest of url third substring.

rewritecond host: (?!www\.)(.*) rewritecond %https (on)|.* rewriterule (.*) http(?2s:)\://www.$1$3 [i,rp] 


(almost done!), doesn't leave subdomains alone. because of (.*) instead of 'example.com', rewrite abc.example.com/whatever... www.abc.example.com/whatever.... if have subdomains leave alone, e.g., staging or localhost developers, or 'shop' hosted shopping domain, can 'or' these 'www' (note localhost doesn't have trailing dot, handle //localhost).

rewritecond host: (?!www\.|staging\.|shop\.|localhost)(.*) rewritecond %https (on)|.* rewriterule (.*) http(?2s:)\://www.$1$3 [i,rp] 

Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -