I've attempted to setup my server with a domain name but am getting a 301 error when typing the URL in the browser. (http://localhost works fine, but http://example.com yields a 301 error).
I have the DNS servers pointed to the correct public IP, and the router set to port-forward incoming 80, to local 80, to the correct private IP.
apache2.conf
has been modified as follows
#<Directory /var/www/>
# Options Indexes FollowSymLinks
# AllowOverride None
# Require all granted
#</Directory>
<Directory /srv/>
Options FollowSymLinks
AllowOverride None
Require all granted
</Directory>
This is for sake of Wordpress being installed at the suggested /srv/www/wordpress/
and not needing the other default Apache location for a website....
wordpress.conf
in the /etc/apache2/sites-enabled/
folder is like the following:
<VirtualHost *:80>
ServerName example.com
ServerAlias *.example.com
DocumentRoot /srv/www/wordpress
<Directory /srv/www/wordpress>
Options FollowSymLinks
AllowOverride Limit Options FileInfo
DirectoryIndex index.php
Require all granted
</Directory>
<Directory /srv/www/wordpress/wp-content>
Options FollowSymLinks
Require all granted
</Directory>
</VirtualHost>
I'm using Ubuntu 20.04, Apache 2.4.41, Wordpress 5.8.1
Update Sept 23, 2021
Edited the title of this question from "Getting 301 Error on Apache Server" to "Localhost is Unreachable with Wordpress". Previously, I had always gotten a mere "timed out" response when entering my domain (http://example.com
) from my local network upon which the server runs. The 301 error came when another, at that time, accessed my domain externally. Now that I've found a way to access my domain externally, the error is a consistent: "Localhost is unreachable". This by the way, only seems to happen on the Wordpress site; when I access the default "It Works" site, it is fine (I've uncommented the apache2.conf
lines I highlighted earlier). Is this perhaps due to Wordpress using a database, and the default hostname
for the user being "localhost"
?
[For those trying to enter the domain pointing to their server: if you're doing this from the same local network upon which the server sits, it will not work (search "NAT loopback" for more on this). That's not the discussion here, but I mention it because it sunk a lot of time; localhost
works, modifying /etc/hosts
can do some cheats--still doens't simulate an external request from my knowledge--, but ultimately, using the domain name will not work.]