Creating a redirect from a different domain on the correct server with web.config -


i have created new site on new domain – have no control on old domain, former host has been kind change dns points correct ip.

as set now, old url shows correct content, uri not change want to. unusual thing in case old url subdomain of domain still in use (but have 0 control over, 301 redirect there impractical).

more concretely, http://subdomain.olddomain.com/ reaches correct ip , shows correct content, there on want redirect http://newdomain.com/

for content redirecting traffic root of new site, might specific page redirects later on.

i've tried variations of in web.config:

<httpredirect enabled="true" exactdestination="true" httpresponsestatus="found">     <add wildcard="^subomain.olddomain.com" destination="http://newdomain.com/" /> </httpredirect> 

i hoping work, unfortunately nothing. if change wildcard *default.htm, redirect, imagine it's not wrong.

i prefer avoid messing iis etc.

what doing wrong?

you make in global.asax , if not enough need perform frame redirect in dns domain. however, if enough can using global.asax this:

    protected void application_beginrequest()     {         if (!context.request.issecureconnection)         {             string url = context.request.url.tostring().replace("://mydomain.", "://mydomain.");             url = url.replace("http:", "https:");             response.redirect(url, true); //true causes current request abort , force instant redirect.         }         else         {             if (context.request.url.tostring().startswith("https://mydomain."))             {                 string url = context.request.url.tostring().replace("https://mydomain.", "https://www.mydomain.");                 response.redirect(url, true);             }         }     } 

this simple example redirect http https (secure) protocol, can used redirect other locations etc. remember if still says old url need frame redirect. according documentation response.redirect occurs in browser.

as last resort can ugly approach (just make behave like):

<!doctype html><html><head><title>dummy</title><meta http-equiv="refresh" content="0; url=http://www.yoururlhere.com/" /></head><body></body></html> 

the last example shows how should return html browser in application_beginrequest if url faulty , execute on client side. or standalone index.htm file work.

if if in iis later: creating rewrite rules url rewrite module

good luck!


Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -