It looks like you're new here. If you want to get involved, click one of these buttons!
Sign In RegisterIt looks like you're new here. If you want to get involved, click one of these buttons!
Howdy, Stranger!
It looks like you've been lurking for a while.
If you register, we also will remember what you have read and notify you about new comments. You will also be able to participate in discussions.
So if you'd like to get involved, register for an account, it'll only take you a minute!
If on your VPS is running Apache web server, you’ll also need to edit the .htaccess file. So to do that, make sure that you can connect to your VPS via root with sudo privileges.
By the way, by default, Apache doesn’t allow the use of .htaccess file, so you will need to enable that.
sudo a2enmod rewrite
sudo systemctl restart apache2
sudo vi /etc/apache2/sites-available/000-default.conf
<Directory /var/www/html> Options Indexes FollowSymLinks MultiViews AllowOverride All Require all granted
After that, restart Apache.
To create the .htaccess file, use this command:
sudo vi /var/www/html/.htaccess
RewriteEngine on RewriteCond %{HTTP_HOST} ^yourdomain.com [NC] RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [L,R=301]
Replace yourdomain.com with your actual domain name and save it.
sudo systemctl restart apache2
If you have VPS with NGINX, follow the tutorial below to redirect non-www URLs to www:
sudo ls - la
sudo nano nginx.conf
server {
server_name yourdomainname.com;
return 301 $scheme://www.yourdomainname.com$request_uri;
}
sudo systemctl restart Nginx
In addition to redirecting non-www to www URLs, you can also run other redirects through NGINX, such as HTTP to HTTPS and other page redirects.