WWW to non www redirect


1. Select redirect type





2. Enter your domain name


Do not include www. Domain name only - e.g. yourdomain.com

3. Get your code

Get .htaccess Code

4. Copy the code to your .htaccess file



ToolsPivot's WWW to Non-WWW Redirect .htaccess Generator creates ready-to-use Apache redirect code that forces all traffic to a single domain format. Type your domain, pick a direction (www to non-www or the reverse), and copy the 301 redirect rules straight into your .htaccess file. Unlike manually writing mod_rewrite syntax, this generator removes the risk of typos that can take your entire site offline.

How to Use ToolsPivot's .htaccess Redirect Generator

  1. Pick your redirect direction: Select either "Redirect from www to non-www" or "Redirect from non-www to www." This tells the generator which domain format becomes your canonical URL.

  2. Enter your domain name: Type just the root domain (for example, yourdomain.com). Don't include http://, https://, or www. The tool adds those parts automatically in the generated code.

  3. Click "Get .htaccess Code": ToolsPivot outputs the full set of RewriteEngine, RewriteCond, and RewriteRule directives in the text box below.

  4. Copy the output: Grab the generated code from the text area. It's formatted and ready to paste with no edits needed.

  5. Add the code to your .htaccess file: Open your site's root .htaccess file through FTP (FileZilla, Cyberduck) or your hosting control panel's file manager. Paste the code at the very top of the file, above any existing rules.

  6. Test both URL versions: Visit www.yourdomain.com and yourdomain.com in your browser. Both should land on whichever format you chose. Use the WWW redirect checker to confirm the 301 status code is returning correctly.

What ToolsPivot's .htaccess Redirect Generator Does

  • Two-direction redirect support: Generate code for www-to-non-www or non-www-to-www. Both options produce a 301 permanent redirect, which is the correct status code for domain consolidation.

  • 301 status code output: Every generated rule uses the R=301 flag. This tells Google, Bing, and other search engines that the move is permanent, passing roughly 90-99% of link equity to the destination URL.

  • Full URI path preservation: The generated RewriteRule captures the complete request path using ^(.*)$ and passes it to the destination with $1. So www.yourdomain.com/blog/post-title redirects to yourdomain.com/blog/post-title, not the homepage.

  • Case-insensitive host matching: The [NC] flag on the RewriteCond line catches domain requests regardless of capitalization. WWW.YourDomain.com and www.yourdomain.com both trigger the redirect.

  • mod_rewrite syntax handling: The generator produces correct Apache mod_rewrite directives, including RewriteEngine On, the %{HTTP_HOST} condition variable, and proper flag placement. No need to memorize regex patterns.

  • Copy-ready formatting: Code appears in a clean text box. No line numbers, no syntax highlighting to strip out, no hidden characters. Select it, copy it, paste it.

Why Use ToolsPivot's .htaccess Redirect Generator

  • Avoid syntax mistakes that crash your site: One misplaced bracket or missing backslash in .htaccess can throw a 500 Internal Server Error across your entire domain. The generator handles the regex so you don't have to touch it.

  • Stop splitting your backlink value: Search engines treat www.example.com and example.com as two separate sites. Every backlink pointing to the "wrong" version is wasted authority. A 301 redirect funnels that equity to one URL. Pair this with the backlink checker to see how your link profile splits between versions.

  • No account, no sign-up, no limits: Enter a domain, get code. That's the whole process. Other redirect generators bundle this feature behind registration walls or push you toward paid plans.

  • Fix duplicate content flags fast: Google Search Console and third-party crawlers like Screaming Frog flag www/non-www duplicates as indexing problems. This redirect eliminates the issue in under a minute. Run the website SEO checker after implementing to confirm the fix.

  • Works alongside HTTPS enforcement: The generated code slots into the same .htaccess file where your HTTP-to-HTTPS rules live. Stack them together for complete URL canonicalization.

  • Saves crawl budget: Googlebot allocates a limited number of requests per crawl session. When it hits the same content on two domain versions, it wastes requests. A single canonical URL means every crawl request counts toward indexing real pages.

What Each Line of the Generated Code Does

If you've never edited an .htaccess file before, the generated code can look intimidating. It's only three lines of active logic, though. Here's what each one does.

RewriteEngine On activates Apache's mod_rewrite module for the directory where the .htaccess file sits. Without this line, every RewriteCond and RewriteRule below it gets ignored completely. Most WordPress installations already have this line present, so check before adding a duplicate.

RewriteCond %{HTTP_HOST} ^www\.yourdomain\.com [NC] sets a condition. The server checks the incoming request's host header. If the domain starts with "www." (the ^ anchor) and matches your domain name, the condition passes. The [NC] flag makes the check case-insensitive. For the reverse direction (non-www to www), this line checks for the bare domain instead.

RewriteRule ^(.*)$ http://yourdomain.com/$1 [L,R=301] performs the actual redirect. The ^(.*)$ pattern captures everything after the domain in the URL. The $1 variable pastes that captured path onto the destination. The [L] flag tells Apache to stop processing more rules. The [R=301] flag sends a "Moved Permanently" header back to the browser and search engine bot.

If your site runs on HTTPS (and it should), swap http:// for https:// in the destination. Or better yet, combine this rule with a separate HTTP-to-HTTPS redirect. Check your SSL certificate status to make sure both www and non-www versions are covered.

Who Needs a WWW Redirect?

Almost every site on an Apache server benefits from this configuration, but some situations make it urgent rather than optional.

New site launches: Set the redirect before any page gets indexed. If Google crawls both versions during the first week, you'll spend months waiting for the duplicate to drop from the index. Agencies building client sites on WordPress, Shopify (with Apache proxies), or custom PHP stacks should treat this as a launch checklist item right next to generating a robots.txt file and submitting an XML sitemap.

After an SEO audit flags duplicates: Technical SEO tools flag www/non-www duplication as a priority issue. Freelance SEO consultants frequently use this generator when onboarding new clients because the fix takes less than 60 seconds but can recover months of lost ranking signals.

SSL certificate installation: Adding HTTPS to a site that never had redirects in place often surfaces the problem. Suddenly there are four reachable versions of every page: http://www, http://non-www, https://www, and https://non-www. A single .htaccess file can collapse all four down to one canonical URL.

WordPress migrations: Moving a WordPress site between hosts or changing domain settings in wp-admin doesn't always create proper server-level redirects. WordPress relies on PHP-level redirects that run slower than .htaccess rules and can fail under certain caching configurations. The .htaccess approach fires at the server level before WordPress even loads.

Multi-domain businesses: Companies managing several TLDs (.com, .co.uk, .com.au) need consistent redirect patterns across all properties. Generating the code per domain takes seconds and keeps every property following the same URL standard. Use the DNS lookup tool to verify each domain's A records point to the right server before applying redirects.

Common Questions About .htaccess WWW Redirects

Is there an SEO advantage to www over non-www?

No. Google's John Mueller has confirmed that neither format provides a ranking advantage. What matters is picking one and redirecting the other with a 301. The consistency itself is the SEO benefit, not the format you choose.

How does ToolsPivot's generator differ from writing the code manually?

The generator handles mod_rewrite syntax, regex escaping, and flag placement automatically. Writing the same three lines by hand is possible, but a single typo (a missing backslash before the dot in your domain, for instance) can trigger a 500 error that takes your entire site down.

Will this redirect work with HTTPS?

The generated code handles the www/non-www portion of the redirect. If your site uses HTTPS, update the destination URL in the code from http:// to https://. You can also stack a separate HTTP-to-HTTPS rule above or below the www redirect in the same .htaccess file.

Can I use this on an Nginx server?

No. This tool generates Apache-specific .htaccess directives. Nginx uses a different configuration file (nginx.conf) with its own redirect syntax. If you're unsure which server your site runs on, check with the hosting checker to identify your web server software.

Where exactly do I put the .htaccess file?

The .htaccess file belongs in your website's document root directory, usually named public_html or www in your hosting file manager. Access it through FTP software like FileZilla or through your cPanel file manager. The file may be hidden by default, so enable "show hidden files" in your client settings.

What if I get a redirect loop after adding the code?

Loops happen when two redirect rules conflict. Check for duplicate rules in your virtual host config or in other .htaccess files in parent directories. Also check if your CDN (Cloudflare, for example) has its own redirect rules that clash. Remove duplicates, clear your browser cache, and test again.

How long until Google picks up the redirect?

Google processes 301 redirects during its normal crawl cycle, which can take anywhere from a few days to several weeks. Speed things up by submitting your preferred URL in Google Search Console and requesting re-indexing of key pages. Use the index checker to monitor which version Google has in its index.

Does the redirect affect page load speed?

A single 301 redirect adds roughly 50-100 milliseconds of latency per request. That's barely noticeable for users. Chained redirects (three or more hops) stack up and can hurt performance. Keep your redirect chain to one hop by combining www and HTTPS rules into a single destination. Test with the page speed checker to measure real impact.

Should I update my sitemap and Search Console after adding the redirect?

Yes. Submit your XML sitemap using only your canonical URL format. In Google Search Console, add and verify both the www and non-www properties, then set your preferred domain. This helps Google process the change faster and confirms your intent.

Can I undo the redirect later?

Removing the redirect is as simple as deleting the three lines from your .htaccess file. Keep a backup of your .htaccess before making any changes. If something breaks, upload the backup through FTP or your hosting file manager and the site reverts instantly. A code comparison tool can help you spot exactly what changed if you're troubleshooting.


LATEST BLOGS

Forget Ahrefs, Semrush & Writesonic: Wix Has Built-In AI Insights

Forget Ahrefs, Semrush & Writesonic: Wix Has Built-In AI Insights

13 Sep  / 1669 views  /  by Nadeem Raza
Top 5 Free SEO Checker Tools to Make Site Auditing Easy

Top 5 Free SEO Checker Tools to Make Site Auditing Easy

3 May  / 4546 views  /  by Nadeem Raza

Report a Bug
Logo

CONTACT US

marketing@toolspivot.com

ADDRESS

Ward No.1, Nehuta, P.O - Kusha, P.S - Dobhi, Gaya, Bihar, India, 824220

Our Most Popular Tools