-1

I was fighting with it for some time but I am unable to find solution and I would like to ask you for your help.

I have my website hosted on PythonAnywhere. I bought a domain from my "local" country seller. I attached it, set cname dns etc. and it is working but only if I write "www." first. I read that PA only accepts this version of address.

I asked my domain provider what can I do about this and he said that I should create .htaccess file to redirect (301) people from domain.com to www.domain.com

I tried many different .htaccess templates with various variations with "1$" and without, still I receive error:

Not Found

The requested resource was not found on this server.

And another weird part for me is that it is "directing" to this address:

https://www.domain.info/home/mynick/domains/domain.info/public_html/www.domain.info

So it is directing to "www." address but it is looking for some weird things in my public_html?

And no matter what I change in my .htaccess this address from above stays the same. What I did wrong?

EDIT:

I am sorry if I did not provide enough information.

I edited file .htaccess in folder "public_html" of my domain.

I tried many different versions like:

Redirect 301 / https://example.com/

And:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain.com
RewriteCond %{REQUEST_URI} !/(.+) [NC]
RewriteRule (.*) http://newdomain.com [R=301,L]

And many other variations but problem from above still exist.

EDIT2:

I also tried these:

RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
Peksio
  • 525
  • 6
  • 25
  • _“What I did wrong?”_ - how could we possibly know, when you completely fail to _show us_ what you did? – CBroe Jun 25 '20 at 08:27
  • I am sorry, I edited my post. – Peksio Jun 25 '20 at 08:32
  • If both the www and the non-www version of the domain resolve to the same directory, then of course the first one will cause a loop. And with the second one, I have no idea what you are trying to achieve with that second RewriteCond there? – CBroe Jun 25 '20 at 08:38
  • My main target is to point users who write "domain.com" to "www.domain.com". It is my first time when I am working with .htaccess so I tried to experiment a little bit but I don't get any feedback. In every example that I tried result is the same. So I started to think that maybe there are other things that I might be doing wrong? – Peksio Jun 25 '20 at 08:45
  • The basic way to do this would be something like https://stackoverflow.com/a/12050652/1427878 If that doesn’t work for you, then that might perhaps have to do with the particular setup of your hosting provider there (“I read that PA only accepts this version of address.”) – CBroe Jun 25 '20 at 08:52
  • Yes, I also checked all of them from this question. I think that problem is connected to the fact that it is pointing to this weird adress in my "public_html". I don't know what may be causing this problem. – Peksio Jun 25 '20 at 08:55
  • `.htaccess` is a file that is used by t – Giles Thomas Jun 26 '20 at 09:56

1 Answers1

0

.htaccess is a file that is used by the Apache web server, and is not applicable to sites that are hosted on platform as a service systems like PythonAnywhere. Instead, what you need to do in order to redirect requests to yourdomain.com (often referred to as the "naked" domain) to www.yourdomain.com is set up an external redirect service. These are normally provided by your domain registrar for free; they might call it something like "web forwarding". However, some of the smaller domain registrars (especially for country-level domains) don't provide it. In those cases, a good free option is the redirection service from Naked SSL.

This help page on the PythonAnywhere site has some extra useful background information.

Giles Thomas
  • 6,039
  • 2
  • 33
  • 51