Redirecting a Web Server’s IP Address to the HTTPS Version of Its Associated Website: 1 Example Using Drupal and 1 Using Publii
In this article, we'll discuss why it's important to redirect all version of your website to the secure version of your website: the one that has a Secure Sockets Layer (SSL) certificate. and that begins with https://.
Assumptions: we have two websites: one is a Drupal website, and the other is a Publii website. Both are hosted on Linodes running the lastest LTS (Long-Term Support) version of Ubuntu. We want all versions of the websites, including the raw ip addresses of the websites, to redirect to the https:// version of each website. Our webserver sofdtware is the latest version of Apache.
What is an SSL Certificate, why is it important, and what is it used for?
An SSL certificate encrypts data exchanged between a website and its users. This keeps sensitive information like passwords and payment details safe from hackers. It also verifies the website's identity, ensuring users are on a legitimate and secure site. The padlock icon and "https" in the URL show this added security. SSL certificates help build trust, especially for websites handling private information or online transactions. They can also improve a website's credibility and search engine ranking by signaling a secure connection.
What is Cerbot, and why do so many websites use it to generate their SSL certificates?
Certbot is a free, open-source tool that automates the process of obtaining and renewing SSL certificates from Let's Encrypt, a widely used certificate authority. Certbot simplifies the installation and management of SSL certificates, allowing websites to enable secure HTTPS connections without manual configuration. Many websites use Certbot because it is easy to set up, free to use, and it automates certificate renewals, ensuring websites remain secure without needing frequent intervention from administrators.
What is Drupal, and why is it so popular for creating websites?
Drupal is a free, open-source content management system (CMS) used to build and manage websites. It is popular because it offers a high level of flexibility, allowing developers to create complex and customized websites with advanced features. Drupal is known for its strong security, scalability, and robust community support. Its modular architecture lets users extend functionality through thousands of add-ons, making it ideal for large organizations, government websites, and businesses needing highly tailored solutions.
What is Publii, and why is it so popular for creating websites?
Publii is a free, open-source static site generator designed for creating and managing fast, secure, and privacy-friendly websites without needing a database or server-side processing. It’s popular because it’s user-friendly, allowing non-technical users to build websites with a drag-and-drop interface while offering powerful features like SEO optimization, customization options, and one-click publishing. Publii generates static HTML files, which makes websites faster, more secure, and easier to host, especially on platforms like GitHub Pages or Netlify. It’s favored by bloggers, small businesses, and users prioritizing speed, simplicity, and security.
What is Linode, and why is it so popular for hosting websites?
- To solve the issue where entering the raw IP address redirects users to
http://example.com
instead ofhttps://example.com
, you can configure Apache to force redirection from the IP address to the HTTPS version of the domain. Here's how you can achieve this:Steps to Redirect IP to HTTPS Version- To solve the issue where entering the raw IP address redirects users to
http://example.com
instead ofhttps://example.com
, you can configure Apache to force redirection from the IP address to the HTTPS version of the domain. Here's how you can achieve this: Steps to Redirect IP to HTTPS Version
- Access Your Server via SSH: Connect to your Linode VPS using SSH.
- Open the Apache Configuration: You need to edit the Apache configuration file. Typically, this file is found in
/etc/apache2/sites-available/000-default.conf
or another file you've configured for your virtual host. - Run: sudo nano /etc/apache2/sites-available/000-default.conf
- Configure Redirection for IP Address: Add the following configuration to redirect traffic from the IP address to
https://example.com
: - <VirtualHost *:80>
ServerName 123.123.123.123
Redirect 301 / https://example.com/
</VirtualHost> - Enable Apache Rewrite Module: If it’s not already enabled, you need to enable the Apache
rewrite
module to handle redirections:- sudo a2enmod rewrite
- Reload Apache: After saving the configuration file, reload Apache to apply the changes:
- sudo systemctl reload apache2
- Now, when a user tries to access your server using the raw IP address (e.g.,
http://123.123.123.123
), they will be redirected tohttps://example.com
, ensuring that all traffic is encrypted and routed through the secure version of your website.Problem #2:
We have a Publii website: https://myblog.com. The IP address of the hosting Linode VPS is 111.111.111.111. Currently, accessing the IP address in a browser takes you to
http://myblog.com
. How can we fix this to redirect users tohttps://myblog.com
?For the Publii website hosted on a Linode VPS using Apache, we follow a similar approach to ensure that accessing the raw IP address redirects users to the HTTPS version of the website.
Steps to Redirect IP to HTTPS Version for Publii
1. Access Your Server via SSH:
ssh username@111.111.111.111
Connect to your Linode VPS using SSH:
Open the Apache configuration file for the Publii site. This file is usually found in/etc/apache2/sites-available/
, named something likemyblog.conf
:- sudo nano /etc/apache2/sites-available/myblog.conf
- Configure Redirection for IP Address:
Add aVirtualHost
block to redirect requests from the IP address tohttps://myblog.com
: - <VirtualHost *:80>
ServerName 111.111.111.111
Redirect 301 / https://myblog.com/
</VirtualHost> - Enable Apache Rewrite Module (if needed):
To handle redirections, make sure the rewrite module is enabled: - sudo a2enmod rewrite
- Reload Apache to Apply Changes:
Save your changes to the configuration file, then reload Apache to apply the new settings: - sudo systemctl reload apache2
- With this setup, any requests made to
http://111.111.111.111
will automatically redirect tohttps://myblog.com
, ensuring a consistent and secure browsing experience for your users.
Summary
Redirecting the raw IP address to the HTTPS version of a website is crucial for maintaining secure connections, consistent branding, and user trust. By configuring Apache correctly, both the Drupal and Publii websites can automatically redirect all traffic, including from their IP addresses, to their secure HTTPS versions, ensuring all users experience the highest level of security and confidence in your site.