Using your .htaccess to remove duplicate content isues with HTTP and HTTPS Drupal 7 links is easily fixed with this technique.
If you’re running a Drupal 7 website with an SSL certificate, you might encounter an issue where your site is accessible via both HTTP and HTTPS URLs. This can create duplicate content problems, negatively impacting your site’s search engine rankings. To prevent this, you need to redirect all HTTP traffic to HTTPS using a simple .htaccess update.
Why Use HTTPS for Your Website?
HTTPS (Hypertext Transfer Protocol Secure) is essential for safeguarding sensitive data transmitted between a user’s browser and your website. Without HTTPS, information can be intercepted, posing security risks. HTTPS is crucial when handling:
- Credit card information
- Session cookies (e.g., PHP session cookies)
- Usernames and passwords
- Personally identifiable information (PII) like names, addresses, emails, passport numbers, or national insurance details
- Confidential content
Implementing HTTPS protects user data, builds trust, and even improves SEO rankings, as search engines favor secure sites. To enable HTTPS, you’ll need to install an SSL certificate on your server.
What’s the Difference Between HTTP and HTTPS?
Most visitors won’t notice significant differences between HTTP and HTTPS sites. The key indicators are the URL starting with https:// instead of http:// and the appearance of a padlock icon in the browser’s address bar, signaling a secure connection.
How to Redirect HTTP to HTTPS in Drupal 7
To ensure all traffic is securely redirected to HTTPS, add the following code to your site’s .htaccess file:
# Redirect to HTTPS
RewriteCond %{HTTPS} off
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
This code checks if HTTPS is off and redirects all HTTP requests to the secure HTTPS version of your site using a 301 (permanent) redirect.
Final Step: Test Your Site
After updating your .htaccess file, test your website by accessing it via http://. You should be automatically redirected to the https:// version. If everything works smoothly, your site is now more secure and SEO-friendly.