Standard web hosts use the Apache webserver software. Most web servers have a hidden file called .htaccess located in the “root” directory. The root directory is normally called “public_html”.

The “public_html directory is where web visitors are directed to by default when they type a domain name in a web browser like Google Chrome or Microsoft Edge.

Rules can be placed in the .htaccess that changes how a web server behaves and what happens when someone visits the website. Forcing the rewrite of HTTP to HTTPS and removing the www prefix if it exists is an example of what type of things can be done using .htaccess.

Insert the code below to the .htaccess file that is located in the web server “root” directory.

# This Rule Directive checks for and removes www if present
# This Rule Directive checks for HTTP and changes to HTTPS if exists
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\.supportforweb\.us [NC]
RewriteRule (.*)$1 [L,R=301]


htaccess testerThe above has been successfully tested using an htaccess Tester. Using this htaccess tester the code can be tested before editing a live .htaccess file. Errors made when editing the .htaccess file can cause server errors. Always make a backup of the working .htaccess before making any changes.

Once you test the code you will see the results htaccess test results

This provides the opportunity to ensure there are no typos or logic errors before making the changes live.

The Debugging info displayed above shows step by step what the htaccess code does. 

1 RewriteEngine On RewriteEngine was now turned on
2 RewriteBase / Using / as the base for the rewrites.
3 RewriteCond %{HTTPS} off [OR] This condition was met.
4 RewriteCond %{HTTP_HOST} ^www\.supportforweb\.us [NC] This condition was met.
5 RewriteRule (.*)$1 [L,R=301] The new url is
Test are stopped, a redirect will be made with status code 301

Spread the love