AllsWeb Blog
No Result
View All Result
  • Home
  • Main Home
  • PHP and MySQL
  • JavaScript
    • jQuery & AJAX
  • WordPress
  • SEO
  • Web Hosting
  • Comparison
Support
Knowledgebase
  • Home
  • Main Home
  • PHP and MySQL
  • JavaScript
    • jQuery & AJAX
  • WordPress
  • SEO
  • Web Hosting
  • Comparison
No Result
View All Result
AllsWeb White Logo
No Result
View All Result
Home Security

Redirect non-www to www & HTTP to HTTPS using .htaccess file

Lakshika Mathur by Lakshika Mathur
January 2, 2020
Reading Time: 2 mins read
0
Redirect non-www to www & HTTP to HTTPS using .htaccess file

The use of .htaccess file is to override the main server configuration. .htaccess file placed in a directory. Therefore, it applies the configuration to that particular directory and all the subdirectories. It is mostly used in Rewriting URLs, Blocking, SSL, Customized error responses, Directory listing, Cache-Control, etc.

RELATED POSTS

Ideas For Ten Fantastic Online Business From Home

Apply these Secrets to Secure your VPS.

What is Software testing?

With the help of this following tutorial will explain to you the most used URL redirection process through the .htaccess file. Firstly, you’ll see how to redirect non-www URLs to www. Secondly, we will show you how to redirect HTTP to HTTPS using .htaccess file.

Creating .htaccess File

Make a file with .htaccess extension in the root directory of the website domain. It can be a simple text file. Therefore, you can edit this file with any text editor.

SEE ALSO: Build an HTML5 Video Player with Custom Controls

Redirect non-www to www

According to the Search Engine prospect, non-www and www URLs are different aspects. So, it can affect site SEO. For example, http://allseweb.com and http://www.allsweb.com are technically different, and when Search Engine fetching the same content from different URLs, treat it as a duplicate content. So, it will be a good idea if you redirect all requests (non-www) to the same URL format (www). Using this file, you can redirect non-www to www URLs.

Add the following code in the root .htaccess file.

RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

SEE ALSO: Create a Digital Clock with Date using JavaScript

Redirect HTTP to HTTPS

If you already have the secure certificate (SSL) on your website, you could redirect visitors to the stable web version. Sometimes SSL encrypted connection is necessary for your website’s visitors. So, it would be best if you forced the visitors to use SSL by automatically redirect HTTP to HTTPS version URL. Also, it is okay if all the URL request is redirected to the HTTPS and www formatted URL.

Add the following code.

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.mysite.com/$1 [R,L]

Note: Please do not forget to replace mysite.com with your site’s domain name.

Also, read our previous blog- Confirmation Before Closing of Tab/Browser using JavaScript

Tags: .htaccess
ShareTweetSendShareSharePinScan
Lakshika Mathur

Lakshika Mathur

Related Posts

Ideas For Ten Fantastic Online Business From Home.
Tutorials

Ideas For Ten Fantastic Online Business From Home

February 10, 2022
25
Apply these Secrets to Secure your VPS. And Tips to Secure your VPS.
Security

Apply these Secrets to Secure your VPS.

February 8, 2022
12
What is Software Testing?, Definition, Types, Importance, and benefits.
Tutorials

What is Software testing?

January 31, 2022
12
How To Choose The Best Server For The cloud?
Interesting Facts

How To Choose The Best Server For The Cloud?

January 31, 2022
23
How to secure the server from unauthorized access?
Security

How To Secure The Server From Unauthorized Access?

January 31, 2022
3
Definition of Cloud Computing. There are Top major features are given.
Security

What is Cloud Computing?

January 31, 2022
6
Next Post
Star Rating System with jQuery, Ajax, PHP, and MySQL

Star Rating System with jQuery, Ajax, PHP, and MySQL

Like Dislike Rating System with jQuery, Ajax, and PHP

Like Dislike Rating System with jQuery, Ajax, and PHP

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Categories

  • Comparison (3)
  • HTML & CSS (9)
  • Interesting Facts (1)
  • JavaScript (27)
    • jQuery & AJAX (18)
  • PHP and MySQL (48)
  • Security (10)
  • SEO (2)
  • Trademark (2)
  • Tutorials (5)
  • Uncategorized (1)
  • Web Hosting (19)
    • VPS Server (5)
  • WordPress (8)

Recent Posts

  • Is the Trademark valuable to your Brand or domain?
  • Ideas For Ten Fantastic Online Business From Home
  • Some best free WordPress Themes for Affiliate Marketing Websites
  • Home
  • Posts
  • Privacy Policy
  • Terms and Conditions

Built and Maintained With ♥ by AllsWeb Team

No Result
View All Result
  • Home
  • Main Home
  • PHP and MySQL
  • JavaScript
    • jQuery & AJAX
  • WordPress
  • SEO
  • Web Hosting
  • Comparison

Built and Maintained With ♥ by AllsWeb Team

Go to mobile version