Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
htaccess redirect www to non www https
The structure of a website’s URL can have a significant impact on its search engine ranking and overall branding. One important consideration in this regard is whether to use the “www” or “non-www” prefix for your site. If you are looking to improve the security and search engine optimization (SEO) of your website, it is recommended to use the non-www prefix. To make this change, you will need to redirect visitors from the www version of your site to the non-www version. In this article, we will guide you through the process of using htaccess to redirect www to non-www URLs for improved website security, branding, and SEO.

1. Introduction to htaccess redirect

- What is an htaccess file?

An htaccess (hypertext access) file is a configuration file used by web servers to modify the server's default behavior. It is a text file that contains directives that tell the server how to handle specific requests.

- Why should you use htaccess redirect?

One of the most common uses of the htaccess file is to redirect URLs. If you have changed your website's domain name or structure, you can use htaccess redirect to ensure visitors are redirected to the correct page. This is particularly useful when redirecting www to non-www URLs.

2. Understanding the difference between www and non-www URLs

- What is a www URL?

A www URL is a type of subdomain that is used to identify a specific web server. The "www" stands for "World Wide Web" and is commonly used to distinguish a website from other web applications, such as FTP servers or mail servers. Examples of www URLs include "" and "".

- What is a non-www URL?

A non-www URL, also known as a naked domain, is a domain name without the "www" subdomain. Examples of non-www URLs include "" and "".

- How do search engines treat www and non-www URLs differently?

Search engines treat www and non-www URLs as separate entities, and they do not share page rank or link equity. If you have both a www and non-www version of your website, search engines will treat them as two separate websites. This can negatively impact your SEO rankings.

3. Benefits of redirecting www to non-www URLs

- Improved website security

Redirecting www to non-www URLs can help improve website security by ensuring that all traffic is encrypted with SSL. This can protect your visitors from cyber attacks, such as man-in-the-middle attacks.

- Better search engine optimization

By redirecting www to non-www URLs, you can consolidate your website's link equity and page rank. This can help improve your website's SEO rankings and make it easier for search engines to crawl your website.

- Consistent website branding

Redirecting www to non-www URLs can help ensure consistent website branding. By using a single domain name, you can improve brand recognition and make it easier for visitors to remember your website's name.

4. Step-by-step guide to redirecting www to non-www URLs using htaccess

- Accessing your server's htaccess file

You can access your server's htaccess file using an FTP client or cPanel file manager. Look for the file named ".htaccess" in your website's root directory.

- Adding redirect code to htaccess

To redirect www to non-www URLs, add the following code to your htaccess file:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^ [NC]
RewriteRule ^(.*)$$1 [L,R=301]

Replace "" with your own website's domain name.

- Testing your redirect

To test your redirect, enter your old www URL into a web browser and verify that it redirects to your new non-www URL. You can also use online tools, such as Redirect Checker, to check that the redirect is working correctly.
5. How to redirect www to non-www URLs for HTTPS sites

Looking to make your website more secure and SEO-friendly? One important step is to redirect URLs from www to non-www, especially for HTTPS sites.

But what's the difference between HTTP and HTTPS redirects, and how can you modify your htaccess code for HTTPS sites?

- Understanding the differences between HTTP and HTTPS redirects

HTTP and HTTPS are both protocols used for transferring information between a web server and a web browser. However, HTTPS is a more secure version of HTTP, using encryption to protect sensitive data from being intercepted by third parties.

To redirect www to non-www URLs for an HTTP site, you would use this code in your htaccess file:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^ [NC]
RewriteRule ^(.*)$$1 [L,R=301]


However, for HTTPS sites, you need to modify the code:

- Modifying htaccess code for HTTPS sites

To redirect www to non-www URLs for an HTTPS site, use this code in your htaccess file:

RewriteEngine On
RewriteCond %{HTTPS} on [OR]
RewriteCond %{HTTP_HOST} ^ [NC]
RewriteRule ^(.*)$$1 [L,R=301]


This code checks if HTTPS is on or if the URL contains "www", and then redirects to the non-www version of the URL with HTTPS.

6. Common issues and troubleshooting tips

Once you've set up your htaccess redirect, you may encounter some common issues. Here are some tips for troubleshooting:

- Common errors and how to fix them

If you're getting a 500 error, it means there's a syntax error in your code. Check for typos or missing punctuation.

If you're seeing no change in your URLs, try clearing your browser's cache and cookies, or try a different browser.

- Checking for redirect loops

A redirect loop is when one URL is redirected to another, which is then redirected back to the original URL in an infinite loop. To check for redirect loops, use a redirect checker tool or check your server logs for multiple redirect requests.

If you do encounter a redirect loop, try removing any conflicting redirect rules in your htaccess file.

7. Best practices for maintaining htaccess redirects

To ensure your htaccess redirects are working properly and efficiently, here are some best practices to follow:

- Keeping your htaccess file organized

Keep your htaccess file organized by grouping similar rules together and adding comments to explain each rule's purpose.

- Regularly checking for broken redirects

Check your website regularly for broken redirects using tools like Google Search Console or Screaming Frog. Fix any broken redirects as soon as possible to avoid negatively impacting SEO.

8. Conclusion and next steps

Redirecting www to non-www URLs for HTTPS sites is an important step in improving website security and SEO. Remember to modify your htaccess code accordingly and troubleshoot any common issues that may arise.

In addition to htaccess redirects, consider implementing other security measures like enabling SSL/TLS, using strong passwords, and updating your website software regularly.

By following these best practices and taking proactive steps to improve your website's security and SEO, you can create a positive user experience and attract more traffic to your site.Redirecting www to non-www URLs using htaccess is an important step in improving your website's security, branding, and search engine optimization. By following the step-by-step guide outlined in this article, you can easily make this change and enjoy the benefits that come with it. Remember to regularly check for any broken redirects and keep your htaccess file organized to maintain the efficacy of your website’s redirect.

Frequently Asked Questions (FAQ)

How do I access my htaccess file?

You can access your htaccess file using an FTP client, such as FileZilla. Alternatively, some hosting providers may offer a file manager in their control panel where you can access and edit your htaccess file.

Can I redirect from non-www to www URLs instead?

Yes, the process for redirecting from non-www to www URLs is very similar. Simply change the redirect code in your htaccess file to redirect to the www version of your site.

Will redirecting from www to non-www URLs affect my website's search engine ranking?

No, redirecting from www to non-www URLs should not have a negative impact on your website’s search engine ranking, provided you implement the redirect correctly and keep your website content consistent.

Will I need to update any links on my website after making this change?

Yes, after making the change from www to non-www URLs, you will need to update any internal links on your website to reflect the new URL structure. If you have external links pointing to your old URL structure, you may also want to consider contacting those site owners and requesting that they update their links.
All resources on the forum clean. Sometimes Virus total give false positives. Also developers may insert backdoors, if you find it, contact me.


Possibly Related Threads…
Thread Author Replies Views Last Post
htaccess code to redirect http to https Shedrach 0 645 05-08-2023, 03:07 PM
Last Post: Shedrach
htaccess Code to redirect url to another url Shedrach 0 590 05-08-2023, 02:59 PM
Last Post: Shedrach

Users browsing this thread: 1 Guest(s)