Forums

i want host my site on naked domain (without www)

and redirect www.my-domain.co to my-domain.co.

(in my case: http://www.to2.co to http://to2.co.)

that important to me become my website is URL Shortener.

how can i do that ?

10x!

Hi there, there's some guidance here - let me know if it helps?

i read carefully page you link. its could be great if you can provide more specific instruction for case i describe.

from that instruction i see that i need to find the ip where my app run.

sub issue:

when i try to use: request.headers['X-Real-IP']

as described here :

https://www.pythonanywhere.com/wiki/WebAppClientIPAddresses

i get the folowing error:

'WSGIRequest' object has no attribute 'headers'

What web framework are you using? DIfferent web frameworks access the headers in different ways.

i use Django.

(request.meta contain 'HTTP_X_REAL_IP' key but its value is 192.115.x.x, and that not what i am looking for i gest.)

X-Real-IP is the IP of the client. I don't understand why you need the IP of your server. That's likely to change on PythonAnyhwere and so any solution that uses the IP address is going to break unexpectedly. You best bet is to use option 1 on this page. To be honest, I'm not sure why we even have option 2 on that page.

i just want to use domain without 'www'.

is that possible on pythonanywhere ? if it is, how can i set that ?

and also redirect http://www.to2.co to http://to2.co

thank you

You can't reliably do that (it's actually a feature built into the DNS system for good reasons). You can redirect to2.co to www.to2.co and just run your app there. Your DNS provider probably has a free domain redirect service that you can set up easily.

My website is URL Shortener. so i try to keep the url as short as i can.

maybe you can to consider to add DNS service to python anywhere.

That's what the redirect is for: You create a link to http://to.co/whatever, when someone clicks it, your DNS provider redirects them to www.to2.co which is running happily on PythonAnywhere.

but i want visitors to see the short to2.co url. when they visit the website.

that how all URL Shortener works

No, URL shorteners show the URL of the URL that was shortened. They just redirect the short URL to a longer one and, after the redirect, the URL in the browser is the original, unshortened URL. The solution I proposed above adds on redirect to the process.

but users in website will see the www domain, and can get a wrong impression. am i right ?

I suppose they might, but they're not going to be copying their shortened URLs from the URL bar, they''ll be copying them from the page where you present them. I'd be massively surprised if 1 in 100 notice that they're on www. instead of the naked domain.

OK thank you for your help

i find some way to solve that by using www.cloudflare.com.

they allowed naked domain as CNAME record.

that was a long search but now you can visit my website on naked domain

to2.co

and short your url easy ;)

in the near future even get some statistic and analysys about who visit the short url