Redirect with code 301

32 views
Skip to first unread message

Alexander Hoch

unread,
Feb 16, 2020, 8:24:57 PM2/16/20
to web...@googlegroups.com

Hi,

I solved the problem:

The controller functions checks for request.env and if its not the domain, web2py will raise an HTTP 301 error and the site will redirected with the request.args.
I will see if google will track this as security issue. My browsers (ie, chrome and firefox) do the redirection without warning.

Here is the code:



def check_host():
   if request.env.http_host != 'www.new_website.de':
       raise HTTP(301,
                  Location = str(URL(c= str(request.controller), f= str(request.function), args= request.args, host='www.new_website.de', scheme='https')))

def index():
   check_host
()

Clemens

unread,
Feb 17, 2020, 5:06:09 AM2/17/20
to web2py-users
Hello Alexander,

what you're trying will be blocked by most browsers since it is security issue. That a website is redirecting the user to another website is always suspicious.

What you can try, is to solve this by a CNAME Resource Record. The other way around redirecting from an outside domain to pythonanywhere is described here:

But just try to contact pythonanywhere's service by writing a mail. They will try to help as they always do.

Best regards
Clemens


On Monday, February 17, 2020 at 2:24:57 AM UTC+1, Alexander Hoch wrote:

Hello,


I tried it with https://www.nakedssl.com/ but this doesnt work as described in https://help.pythonanywhere.com/pages/NakedDomains for me.

There is another suggestion in deploying a flask app and redirect with the this sample code: https://help.pythonanywhere.com/pages/RedirectWebApp/
Is there an equivalent solution in web2py? or is there some possiblity to change routes.py to redirect a request.env to the new  "www.newwebsite.de/.../123/=abc".  with variables, functions and argument.
This is too difficult for hobby programmer. I really would appreciate your help.

Cheers ;)
Reply all
Reply to author
Forward
0 new messages