Forums

How to make redirection work?

Hello, I had the smoothest experience on PythonAnywhere. Now I am thinking to start a custom account here but before that I wanted to make sure that all was working fine for me. So zerop.pythonanywhere.com hosts a web based RESTful API. So for example when I type: curl -i zerop.pythonanywhere.com/appname/number/12344 , I get back the results as I intend to.

Now I have registered a domain name(let's say mywebsite.com) ,I want to point the subdomain api.mywebsite.com to my PA site. I have made it's CNAME record point to my PA site. I typed: curl -i api.mywebsite.com/appname/number/1234 But now the result is this:

HTTP/1.1 301 Moved Permanently
Cache-Control: max-age=900
Content-Type: text/html
Location: http://zerop.pythonanywhere.com
Server: Microsoft-IIS/7.5
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET

Date: Mon, 04 Aug 2014 20:16:12 GMT Content-Length: 0 Age: 0 Connection: keep-alive

So those are the redirection headers which I get. It's ok for people visiting my site with browsers but for those who would be using the API, that's a lot of problem. Any workaround for it? Thanks, would be grateful to you.

Who or what will be using your API?

Whether it's a problem will depend on whether the consuming program will follow the redirect (properly!) or go 'this isn't what I wanted, what the hell does HTTP 301 mean?'.

I wanted it to be as simple as possible. The users would have sent their request and get their results in return. But redirection adds another layer of complexity.

I think the problem is becuase PA doesn't have its own nameservers? If it had then I could just change the nameserver of my domain to my site here and it would have worked without redirection;

If you're getting that redirect, it means that you haven't set up a CNAME, you've set up a domain redirect. If you set up the CNAME correctly and have a web app configured for api.mywebsite.com, you won't have that issue.

Here is the snapshot of my CNAME list in godaddy:

http://s22.postimg.org/msc1kj6kh/snapshot.png

I have made the subdomain api point to zerop.pythonanywhere.com

But I get redirected to this whenever I go to api.mysite.com, https://www.pythonanywhere.com/domain_not_found/

I just noticed that you have a free account, so you can't create a web app on your own domain. You can still use the domain redirect that you originally had, but that will (as you've noticed), still be a redirect and not a direct access to your api.

@glenn

Just to be sure: If I upgrade to custom account then my solution(the CNAME record i added) will work right away, right?

Not right away, you'd need to create a web app for your domain. If you want to keep zerop.pythonanywhere.com, you'd need a Custom account with 2 web apps, then you can just create a new web app at api.mywebsite.com and copy the wsgi file from zerop.pythonanywhere.com. Then everything will just work.