How to Redirect your Domain Using .htaccess File

This article will explain how to redirect your domain using .htaccess file using common .htaccess redirects rules.

.htaccess is a configuration file for use on web servers running the Apache Web Server software.

Since .htaccess is a hidden system file, please make sure your FTP client is configured to show hidden files. This is usually an option in the program’s preferences/options.

Redirect HTTP Requests to HTTPS

In order to redirect your website to be opened through HTTPS, you should add the following rewrite rule to your .htaccess file:

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule .* https://www.yourdomain.com%{REQUEST_URI} [R,L]

This will redirect your domain to https://www.yourdomain.com

 

If you wish the redirect to work without www, you should remove it from the rewrite rule:

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule .* https://domain.com%{REQUEST_URI} [R,L]

This will redirect your domain to https://domain.com


  • 0 Users Found This Useful
Was this answer helpful?