I have an Apache server, where the root website directory is located at /var/www/html/. I have a domain I purchased on GoDaddy that contains an @ A record which points to my home IP Address where my server is located. On the server end, I have a private folder inside my website directory protected correctly with a username and password, as you'll see in my server configuration. I noticed that when I go to my domain with Chrome, sometimes it will load instantly, and other times (according to the Google Chrome Developer Network Console) I will keep getting a "301 Moved Permanently" status code from my server. Is there something I am overlooking?

My website conf file (replaced with example.com for temporary privacy):

<VirtualHost *:80># The ServerName directive sets the request scheme, hostname and port that# the server uses to identify itself. This is used when creating# redirection URLs. In the context of virtual hosts, the ServerName# specifies what hostname must appear in the request's Host: header to# match this virtual host. For the default virtual host (this file) this# value is not decisive as it is used as a last resort host regardless.# However, you must set it for any further virtual host explicitly.ServerName www.example.comServerAlias example.comServerAdmin [email protected]DocumentRoot /var/www/htmlErrorDocument 404 /404.html <Directory "/var/www/html/private">AuthType BasicAuthName "Restricted Content"AuthUserFile /etc/apache2/.htpasswdRequire valid-user</Directory># Available loglevels: trace8, ..., trace1, debug, info, notice, warn,# error, crit, alert, emerg.# It is also possible to configure the loglevel for particular# modules, e.g.#LogLevel info ssl:warnErrorLog ${APACHE_LOG_DIR}/error.logCustomLog ${APACHE_LOG_DIR}/access.log combined# For most configuration files from conf-available/, which are# enabled or disabled at a global level, it is possible to# include a line for only one particular virtual host. For example the# following line enables the CGI configuration for this host only# after it has been globally disabled with "a2disconf".#Include conf-available/serve-cgi-bin.conf</VirtualHost># vim: syntax=apache ts=4 sw=4 sts=4 sr noet

And here is the .htaccess file located at the root of my website, which might help:

RewriteEngine onRewriteCond %{HTTP_HOST} ^example.comRewriteRule ^/(.*)$ http://www.example.com/$1 [L,R=301]
1

Best Answer


I finally found a working solution. It wasn't the server's fault, it was the way I set up GoDaddy. Inside your domain's DNS settings, have the server permanently redirect to your public IP address. Ensure it is a masked redirection so that your domain stays in the web address bar.