Non WWW to WWW redirect loop

April 4, 2015 946 views
Apache DNS Ubuntu

Hi guys.
Just created droplet with Ubuntu (14.04) and have OpenCart installation with Apache as described on this site.

Everything is looks OK on www.mysite.com, but if I goes to mysite.com domain, I get "Font from origin 'http://www.mysite.com' has been blocked from loading by Cross-Origin Resource Sharing policy".

Made some (very long) search (it's my first day with servers) and got a solution : to redirect non WWW to WWW.

My /etc/apache2/sites-available/000-default.conf:

<VirtualHost *:80>
ServerAdmin myemail@email.com
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

## Added by me
ServerName mysite.com
# ServerAlias www.mysite.com
# Redirect permanent / http://www.mysite.com/

Tried the "ServerAlias www.mysite.com" but doesn't helps.
If I uncomment this line "Redirect permanent / http://www.mysite.com/" and restarts the server, when I goes to mysite.com it redirects me ( 301 ) to www.mysite.com but I get "This webpage has a redirect loop", and in dev tools: too many redirects.

Tried changes on .htaccess in /var/www/html/ but it looks doesn't work at all (adding and removing junk chars does not make changes)

What can be the next step to resolve the issue?
Is there some more information that I need to provide?

Thank you in advance for your time.

1 comment
Be the first one to answer this question.