Learn Digital Marketing Online

Http To https Redirect htaccess & www to non www URL

3 5,980

Many users have confused between HTTP to https redirect htaccess & www vs non-www URL, and this question has asked many times which URL pattern should prefer for better SEO ranking advantage. My article helps you to clear your confusion.

First, we need to know from where the confusion has started for HTTP and www vs non-www URL.

HTTP to https Redirect htaccess & www vs non-www URL better for SEO ranking

This confusion has started when you add your WordPress website URL into Google webmaster tools. It’s given the options to set your preferred domain (www or non-www URL). So most users got confused about what to select mostly newbies.

Definitely, there are some cons and pros for www to non-www URL and their solution too. Otherwise, there is no extra benefit. It is only your preference which you select. There are two types of impact one is for SEO and the second for technical.

HTTP to https redirect htaccess & www vs non-www URL

http to https redirect htaccess

Which is better URL www to non-www for SEO ranking

If you are going to set up your new website, I will suggest you use Http to https redirect htaccess code for www to non-www in your URL on your website, www URL having some benefit or logical advantage over non-www sites.

When you are going to start SEO of your site, you optimize the load time and speed of your website and you want your site respond fast to your users.

When we jump to link building and directory submissions, some of the directories will force you to add a proper URL including www.

Yes, this is the logical point when you have to use unnecessary www for getting a backlink to your website.

And when any user will click on generated backlink a request will go to your web server with the www and your server returns a non-www URL.

Editing .htaccess File

  1. Download the .htaccess file from the server edit and upload it to the server using FTP.
  2. Use the “FileZilla” FTP program that allows you to edit a file remotely.
  3. Use a VI or Nano editor and SSH to edit the file.
  4. Use the File Manager in cPanel to edit the file.

The solution for this you have to set a canonical link tag in your head/header file. This means you are adding a server-side HTTP to https redirect 301 on your website. That is why we suggest you use www to non-www URL on your site.

The second part of the difference between www to non-www URL is technically more flexible with DNS.  When you register any domain name it comes without www, and when you host it with www then www consider as your hostname and serves all the content to the public.

If you are using your site with www hostname that will help in the file structuring of the WordPrss website. It also has the ability to restrict cookies when you use multiple sub-domains.

http to https redirect apache virtual hosts

<VirtualHost *:80>
   ServerName mysite.example.com
   Redirect permanent / 

<VirtualHost _default_:443>
   ServerName mysite.example.com
   DocumentRoot /usr/local/apache2/htdocs
   SSLEngine On
# etc...

Redirect www to non-www

The non-www URL is referred to as naked URLs, and the naked domain would not have CNAME benefits. As above I already suggest you if you are building your website from scratch then use www in that.

And if you already have a WordPress website and want to change it will directly impact your current website rank and you have to pay attention more to do change the canonical URL. You also have to spend more time to get your rank back.

Here is the code to redirect http to https redirect htaccess

<IfModule mod_rewrite.c>

RewriteCond %{HTTPS} off

RewriteCond %{HTTP_HOST} !^www.(.*)$ [NC]

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


RewriteCond %{HTTPS} on

RewriteCond %{HTTP_HOST} !^www.(.*)$ [NC]

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


HTTP to https redirect htaccess

<IfModule mod_rewrite.c>

RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]



<IfModule mod_rewrite.c>

RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ [R=301,L]


http to https redirect nginx

To enforce an HTTP to HTTPS redirect, you need to edit the Nginx configuration file.

In most cases, you can locate the file in the /etc/nginx/sites-available directory. If not found, search for it here: /etc/nginx/nginx.conf, /usr/local/nginx/conf, or /usr/local/etc/nginx.

sudo nano /etc/nginx/sites-available/server.conf

sudo service nginx restart

Nginx Redirect all HTTP traffic to HTTPS

Open the Nginx configuration file for editing, then insert the following code:

server { listen 80 default_server; server_name _; return 301 https://$host$request_uri; }

Here is a breakdown of the commands:

  • Listen 80: This instructs the system to catch all HTTP traffic on Port 80
  • Server_name _;: This will match any hostname
  • Return 301: This tells the browser (and search engines) that this is a permanent redirect
  • https://$host$request_uri: This is a short code to specify the HTTPS version of whatever the user has typed

After editing, all traffic for the HTTP default server redirects to HTTPS.


http to https redirect htaccess is your preferred choice for Google, there are no benefits in terms of the Google ranking. But there are several technical benefits on www over non-www URLs websites. If you know about any other differences and benefits let us know by comments.

If you find this article use full for you, please subscribe and share it with others to help them.

Become An Expert in Digital Marketing
Enter your email below to get WordPress, SEO and traffic tips
You can unsubscribe at any time
Leave A Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

  1. jitun nahak says

    Thanks for sharing this submission sites, it’s very helpful for me to improve the website ranking, once again thank you. keep it up..

  2. mindmadetechnologies says

    All your listings are highly useful for us , Great effort and good work , Thanks for sharing

  3. serpranker says

    Highly excited to share comments on your website blogs , thanks for postings