Here's how you can do it:
- SSH into your Ubuntu server.
- Open the Apache configuration file for your website. The file is usually located in the
/etc/apache2/sites-available/directory and has a
.confextension. For example, if your website is called "example.com", the configuration file may be named
- Edit the configuration file using a text editor like
vi. For example:shell
sudo nano /etc/apache2/sites-available/example.com.conf
- Look for the
<VirtualHost>section for your website. It typically starts with
<VirtualHost *:443>for HTTP and HTTPS respectively.
- Within the
<VirtualHost>section, add the following lines to redirect all requests to the "www" version of your website:apache
<VirtualHost *:80> ServerName example.com
Redirect permanent / http://www.example.com/ </VirtualHost>
example.comwith your actual domain name.
- Save the configuration file and exit the text editor.
- Enable the new configuration by creating a symbolic link to the
sudo a2ensite example.com.conf
example.com.confwith the actual name of your configuration file.
- Restart Apache for the changes to take effect:
sudo service apache2 restart
Now, when you access your website without the "www" prefix, it should automatically redirect to the "www" version, where your Django application is hosted.