asp.net - How to transfer/redirect calls without www to www.domain.com -
i have website in asp.net. want calls to: domain.com redirected www.domain.com
i found here following:
rewriteengine on rewritecond %{http_host} !^www. rewriterule ^ http://www.%{http_host}%{request_uri} [l,r=301]
however, might cause problem when using subdomain xx.domain.com
thanks
you can use code asp.net application @ global.asax file:
void application_beginrequest(object sender, eventargs e) { string fromhomeurl = http://yourdomain.com; string tohomeurl = http://www.yourdomain.com; if(httpcontext.current.request.url.tostring().tolower().contains(fromhomeurl)) { httpcontext.current.response.status = "301 moved permanently"; httpcontext.current.response.addheader("location", request.url.tostring().tolower().replace(fromhomeurl, tohomeurl)); } }
Comments
Post a Comment