NetTalk Central

NetTalk Web Server => Web Server - Ask For Help => Topic started by: ianburgess on June 28, 2012, 02:02:14 AM

Title: Redirect non-secure URL to https
Post by: ianburgess on June 28, 2012, 02:02:14 AM
I have a domain that is pointing to the IP address of the PC running the Nettalk Webserver. The webserver is monitoring Port 443 and using SSL, so is accessed by typing https://mydomain.com in their browser.

I would like to set things up so that if a user goes to mydomain.com or www.mydomain.com - ie. not the secure URL, they are automatically redirected to the https URL or there is a landing page that they can then click on a link to the https URL.

Any suggestions as to how to do this in a single Nettalk webserver app?
Title: Re: Redirect non-secure URL to https
Post by: Matthew on June 28, 2012, 03:47:14 AM
Hello Ian

Did You check AlwaysSSL (9) and MixedSSL (8) examples of NetTalk Web Server?

It's shows how to make redirection to the SSL site using Template settings of NetWebServer class.

Regards,
Matthew
Title: Re: Redirect non-secure URL to https
Post by: Bruce on June 29, 2012, 03:49:30 AM
yes, although both those examples need updating I think.
the preferred approach now is to create a second window, with a second web server object on it, pointing to the same webhandler procedure.

cheers
Bruce
Title: Re: Redirect non-secure URL to https
Post by: ianburgess on June 29, 2012, 04:14:09 AM
yes, although both those examples need updating I think.
the preferred approach now is to create a second window, with a second web server object on it, pointing to the same webhandler procedure.

cheers
Bruce


Thanks Bruce. I have tried that and I can get the webserver to respond to either port 443 (SSL) or 88 (non SSL). What I need to happen is that if a user accesses the non SSL (port 88 or whatever) version, they are redirected automatically to the SSL version. How could I achieve that?
Title: Re: Redirect non-secure URL to https
Post by: Bruce on July 01, 2012, 11:27:08 PM
so, on the "non secure" side, you have the default page set with something like;

p_web.Script(p_web.WindowOpen('https://home.whatever.com'))

the s, in https is the important bit.

If you're a bit cunning you could put something like this in your 404 error packet for the non-secure site, then it'd work with all pages, not just the home page.

cheers
Bruce
Title: Re: Redirect non-secure URL to https
Post by: ianburgess on July 02, 2012, 12:36:34 AM
Ok thanks. Where in the Webserver procedure would you embed the script? Also, what would you put in the "Default Page" in the Webserver template>
Title: Re: Redirect non-secure URL to https
Post by: Bruce on July 02, 2012, 05:22:40 AM
Hi Ian,

See the Error example for an example of crafting a custom 404 page.
If you have this you can set the default page to anything you like - eg
'Indexpage'

cheers
Bruce
Title: Re: Redirect non-secure URL to https
Post by: ianburgess on July 02, 2012, 05:27:43 AM
so, on the "non secure" side, you have the default page set with something like;

p_web.Script(p_web.WindowOpen('https://home.whatever.com'))


Thanks bruce, I meant where do you embed the WindowOpen script and would this override the "default page" as set in the template?