NetTalk Central

Author Topic: Redirect non-secure URL to https  (Read 5228 times)

ianburgess

  • Full Member
  • ***
  • Posts: 119
    • View Profile
    • Email
Redirect non-secure URL to https
« 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?

Matthew

  • Full Member
  • ***
  • Posts: 137
    • View Profile
    • Email
Re: Redirect non-secure URL to https
« Reply #1 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

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11250
    • View Profile
Re: Redirect non-secure URL to https
« Reply #2 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

ianburgess

  • Full Member
  • ***
  • Posts: 119
    • View Profile
    • Email
Re: Redirect non-secure URL to https
« Reply #3 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?

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11250
    • View Profile
Re: Redirect non-secure URL to https
« Reply #4 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

ianburgess

  • Full Member
  • ***
  • Posts: 119
    • View Profile
    • Email
Re: Redirect non-secure URL to https
« Reply #5 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>

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11250
    • View Profile
Re: Redirect non-secure URL to https
« Reply #6 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

ianburgess

  • Full Member
  • ***
  • Posts: 119
    • View Profile
    • Email
Re: Redirect non-secure URL to https
« Reply #7 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?