How do I redirect non www to www

Website URL

https://alvinsworldofmathematics.rf.gd

Error Message

No error message, but a question, how do I redirect my site from alvinsworldofmath.rf.gd to www.alvinsworldofmath.rf.gd?

Other Information

Will this help with indexing?

non www and www has no difference in search indexing.
you can redirect to www with this htaccess code:

RewriteEngine On
RewriteCond %{REQUEST_URI} !^/(robots\.txt|favicon\.ico|sitemap\.xml)$
RewriteCond %{HTTP_HOST} !^www\.askapache\.com$ [NC]
RewriteRule ^(.*)$ https://www.askapache.com/$1 [R=301,L]
2 Likes

Kind of wrong. If you are serving the same content over two subdomains, that can turn into issues with Google selecting main and canonical links.

It is always best to use either www., or no www. It does not really matter which one though.

5 Likes

I put that code in and I had to remove it because it made my site redirect to askapache.com!

The code is fine, but it’s example code. You’re supposed to replace the www.askapache.com parts with your own domain.

Here is some alternative code that doesn’t hard-code a website URL in your .htaccess code:

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
4 Likes

Uh, that code made my site not work AT ALL. I yet again had to remove it.

Can you please elaborate on what you mean by “not work”? Did it show you an error message?

3 Likes

By not working, uh it made the site not load and instead the browser kept throwing errors.

It would be really helpful if you shared those errors instead of just saying “it does not work”

4 Likes

Never mind! I managed to do it.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.