NetTalk Central

Author Topic: How to do a 301 Redirect from "www" to "root"?  (Read 2594 times)

Stu

  • Hero Member
  • *****
  • Posts: 509
    • View Profile
    • Email
How to do a 301 Redirect from "www" to "root"?
« on: December 07, 2016, 02:52:24 PM »
Hi Bruce/Folks,

Specific question (arising out of another post below).

What's the best way to do a 301 Redirect for "www" urls pushing them to the "root" (non-www) urls?

(https://support.google.com/webmasters/answer/93633)

I've gone through the webhandler embeds that I do use for redirecting and doing lots of magic stuff. But am not sure of the right place to be able to adjust the "www".

Cheers.
Cheers,

Stu Andrews

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11191
    • View Profile
Re: How to do a 301 Redirect from "www" to "root"?
« Reply #1 on: December 12, 2016, 02:12:14 AM »
so the call is

p_web.Redirect(toURL)

I think the best place for it is in WebHandler, _SendFile, after loc:filename is set...
something along the lines of

  if lower(sub(loc:filename,1,3)) = 'www'
    self.redirect....
    return
  end


cheers
Bruce

Stu

  • Hero Member
  • *****
  • Posts: 509
    • View Profile
    • Email
Re: How to do a 301 Redirect from "www" to "root"?
« Reply #2 on: December 13, 2016, 01:46:53 PM »
Thanks Bruce, really appreciate this.

What's cool is that the solving of the relative urls issue (other thread) meant this no longer was something that needed to happen. Thankfully.

But is a great piece of info/how-to to have on the forum.

Cheers.

Stu
Cheers,

Stu Andrews