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
offer web hosting offer web hosting offer web hosting
ADVERTISEMENT
Home Security

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

Lakshika Mathur by Lakshika Mathur
January 2, 2020
Reading Time:2min 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

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.

1
2
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.

1
2
3
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

November 23, 2019
15
Secrets you can apply to secure your VPS
Security

Apply these Secrets to Secure your VPS

November 17, 2019
2
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 *

Popular Posts (Last 7 Day)

Like Dislike Rating System with jQuery, Ajax, and PHP

Like Dislike Rating System with jQuery, Ajax, and PHP

January 6, 2020
72
Star Rating System with jQuery, Ajax, PHP, and MySQL

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

January 6, 2020
15
Redirect non-www to www & HTTP to HTTPS using .htaccess file

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

January 2, 2020
4
Confirmation Before Closing of Tab/Browser using JavaScript

Confirmation Before Closing of Tab/Browser using JavaScript

January 2, 2020
19
Build an HTML5 Video Player with Custom Controls

Build an HTML5 Video Player with Custom Controls

January 2, 2020
17
Create a Digital Clock with Date using JavaScript

Create a Digital Clock with Date using JavaScript

January 2, 2020
31

Categories

  • Comparison (2)
  • HTML & CSS (9)
  • JavaScript (27)
    • jQuery & AJAX (18)
  • PHP and MySQL (47)
  • Security (2)
  • SEO (2)
  • Trademark (1)
  • Tutorials (2)
  • Web Hosting (8)
    • VPS Server (2)
  • WordPress (5)

Recommended Stories

Live Image Upload

Live Image Upload, Crop and Resize using jQuery and PHP

December 24, 2019
4
Auto Resize Textarea Height using jQuery

Auto Resize Textarea Height using jQuery

December 28, 2019
0
Best WordPress Security Tips Without and With The Use Of Plugins

Best WordPress Security Tips Without and With The Use Of Plugins

November 30, 2019
0

Popular Stories

  • Ajax Pagination with Search and Filter in PHP

    Ajax Pagination with Search and Filter in PHP

    0 shares
    Share 0 Tweet 0
  • Autocomplete Textbox with Multiple Selection using jQuery in PHP

    0 shares
    Share 0 Tweet 0
  • Image Gallery CRUD with PHP and MySQL

    0 shares
    Share 0 Tweet 0
  • One Time Temporary Download Link with Expiration in PHP

    0 shares
    Share 0 Tweet 0
  • Create PDF with Watermark in PHP using Dompdf

    0 shares
    Share 0 Tweet 0
  • 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