Redirect www To Non www
Or Back Again, With a Single Redirect
The generator creates the rules for redirecting www to non-www, or vice versa, and forcing HTTPS at the same time. This is done through either Apache or Nginx, with a line indicating what will happen to each of the four possible URLs.
- FreePrice
- 2Servers
- 1Hops
- NoneUploads
www and Non-www Redirect Generator
One canonical host, in a single hop
Just the name. No scheme, no slash, no path.
What happens to each addressBack up the file you are editing first. A redirect rule with a mistake in it can take a whole site offline, and the fix is hard to reach once it has.
Ready. Type your domain and pick which version should win.
Check before you publish
One wrong line in a server, robots or DNS file can hide pages from search or stop mail from arriving. Test the result on a staging copy, or with a checker, before it goes live.
How to fix the errors this tool finds
Short guides, each with a quick video, for the issues this check can flag.
Redirect Chain: How to Fix ERR_TOO_MANY_REDIRECTSWhy redirect loops happen, how they hurt your SEO and speed, and how to fix them in your server rules.
13 minutes of reading · video guide inside
Why One Host Has To Win
A site usually answers on four addresses: http and https, each with and without www. All four show the very same pages.
Search engines consider both of these results to have the same info, so they select only one. This selection could be different from the option you would have chosen.
Analytics splits visits across them. Cookies set on one are not read on another. Links accumulate against whichever version people copied, and each new link starts the same argument again.
So pick one and redirect the rest. Google's guidance on 301 redirects covers the mechanics; this page covers the rules that implement it.
www Or Not: It Doesn’t Matter, And Yet It Does
Both choices work just as well. Choose one, then stick with it forever; changing it will need a redirect for every email address that you have.
There’s one technical difference. Under original DNS rules, a bare domain cannot contain a CNAME record at the apex; this is important when using a CDN for your website.
Most hosts have worked around this issue using their own record types. If yours has not, select "www."
Why One Hop Rather Than Two
The obvious way to write this is with two rules, one that forces HTTPS and the other that settles the "www" part of the domain name. A user visiting http://www.example.com will travel through both rules.

If there are two redirects, then you’re making two round-trips to get to where you want to render, and on a potentially slow connection, you’ll also have an audit reporting that you have a redirect chain.
The rule sets the scheme and the host at once, so the worst possible case is a single hop from any location. The mod_rewrite documentation describes each directive.
What To Check Once The Rule Is Live
Try each of the four possible ways to enter your URL manually (with "www" or without, using "http://" or "https://") to make sure each method will result in a direct redirect to your site.

Afterwards, also try testing an internal page. If you use a rule to drop the path of your URLs, all traffic will go through the home page, which will slowly kill off each of your existing links.
Check the query string here as well! If you lose ’?utm_source’ it will break your campaign reports and no one will realize for a month.
Update the canonical tag, sitemap and search console properties. Redirecting users is just a portion of the total task.
Test With 302 First
Browsers cache a 301, sometimes for months. Get it wrong and visitors keep following the old rule long after you fixed the file. Trial it as a 302 before making it a 301.
Where These Rules Go
On Apache, put the code into.htaccess in the document root before any code a CMS added. Just, WordPress rewrites all code that is placed below its own marker.

On Nginx, in the server configuration and not in a.htaccess file, as there is no per-directory configuration for Nginx. Once you’ve saved, restart your web server.
In managed hosting, check your control panel for a canonical host option before checking your configuration files. If you find such an option, use that rather than your config file.
What to Check Once You Have Pasted
Type all four addresses into a browser, one at a time. Each should land on the winner, and the address bar should show it after a single hop.
Then run the redirect chain checker for the two URLs that are redirected. A single redirection step indicates the destination URL; two redirection steps mean there is a conflict between this redirect rule and another redirect rule.
Check another level down as well as the home page. A drop in the path rule will send all deep links back to the front page, which the search engines will interpret as a "soft 404".
Finally, look at your internal links. Every one pointing at the old host now costs a redirect that nobody needs.
Back The File Up
If there’s one error made when creating redirect rules, it will bring down your entire website (even your administration page) which you need to access to repair the problem. So, keep copies of files and be able to find those files using methods other than a browser.
How the www and Non-www Redirect Generator Works, Step by Step
This brief video shows each step from start to finish. Choose your language below, and switch on captions if they help.
Writing the www Redirect Rule
The four steps above show how every address is modified before being pasted into the left-hand panel.
Type your domain
Just the bare domain name, for example example.com. Do not include https://, www or any paths. All other inputs will be given as a full sentence, not as a command.
Pick the winner
Either the naked domain or the www host; which ever is chosen will redirect all requests for the other from that point forward.
Choose your server
Apache creates a.htaccess block, while Nginx creates two server blocks. Each block can be used with a single-tier architecture (i.e., one in front of the other).
Back up, paste, test
Keep a dated copy of the config first. Then paste, reload, and check all four addresses reach the one you picked in a single hop.
What Sets This Redirect Generator Apart
Copying a rule off a forum takes ten seconds. These are the differences worth the extra minute.
One hop, not two
One single term determines both the plan and the computer, so there will be no chaining through two redirection steps during entry.
Apache and Nginx
Both of those syntax’s are used in the same field. One half of the internet is running one, the other half is running the other.
The four addresses shown
The panel will show you how each of your four versions of the domain is being processed before pasting.
Your domain escaped properly
The tool escapes the "." in a regular expression. The tool will also refuse to write into a live config anything other than a simple domain name.
Permanent 301 or temporary 302, whichever you need
Browsers keep 301 redirects in place for an extended period of time. This gives the chance to test out potential changes using a temporary redirect instead of making a full redirect change.
Comments you can keep
Each of the blocks arrives with short line-by-line descriptions of how it works. That’s exactly what the next person who opens this file is going to need to know.
Rules For Canonical Host Redirects
The eight items which can make a redirect from a risk to a five-minute task.
- Download a copy of your config file before you change it. A broken rule can lock you out of the site, including the admin page. Keep a copy and know how to reach the file without a browser.
- Put the block above the CMS rules. WordPress processes everything below its own marker. So, a rule placed after that marker will never be executed.
- Test with 302 before 301. Browsers cache a permanent redirect for a long time, and a mistake then follows your visitors around for weeks.
- Check all four addresses. All four hosts: http, https, www, and bare. Enter each into your browser once and verify that you land on the winning host in only one step.
- Update the canonical tags too. A redirect is used to work out how to handle a request. A canonical tag is used to work out what the page states about itself. These two tags must be consistent with each other.
- Update Google Search Console once you switch. Verify both versions as properties, so you can watch the traffic move rather than guess at it.
- Update your internal links to the chosen version. Every internal link pointing at the old host costs a redirect. A search and replace in the database removes them all.
- Handle the redirect on the server, not in the page. A plugin or a script can do this, and both run after PHP has started. A rule in the server config answers before any of that loads.
- Watch for a second rule competing. Hosting panels add their own canonical host settings. Two rules disagreeing is how a site ends up in a redirect loop.
- Never change your mind twice. Each switch costs a redirect on every address you own. Choose one version, record the choice and never flip it.
Six Redirect Mistakes That Cost Traffic
The first two take a site offline. The rest take months to notice.
A redirect loop
A rule that sends the winner back to itself. The browser gives up, and every page on the site is unreachable.
Rules below the CMS marker
WordPress owns everything under its block. Rules pasted there look right in the file and never run.
A double redirect where one would do
Scheme in one rule, host in another. Every visitor arriving at the wrong version pays for two round trips.
Pointing all retired pages at the home page
A rule that drops the path sends every deep link to the front page, and search engines treat that as a soft 404.
Forgetting internal links
The redirect works, and every internal link still takes a detour through it. A database replace fixes the lot.
A 301 while still testing
Browsers cache it for months. Your own machine keeps following the old rule long after the file itself changed.
Redirect Questions People Ask
Is it best to redirect www to non www, or to point non www at www?
Either. Neither ranks better, so pick one and stay with it. www gives you an easier life when a CDN sits in front, because of how DNS handles the apex of a domain.
Does moving www to non-www cost me rankings?
A permanent redirect passes the signals across. Leaving four versions of a site answering hurts more, because they compete with each other.
Where does the htaccess www redirect go?
In .htaccess at the document root, above any block your CMS added. WordPress rewrites everything under its own marker, so a rule below it may never run.
Why does my redirect go through two hops?
Because the scheme and the host are handled by separate rules. The block here decides both at once, so the worst case is one hop.
Is a 301 or a 302 right for a www redirect?
A 301 once you are sure, since it is permanent and consolidates the signals. Test with a 302 first, because browsers cache a 301 for a very long time.
Do I need a canonical tag as well?
Yes. The redirect settles the request and the canonical tag settles what the page claims about itself. Make sure both point to the same version.
What about my non www redirect on Nginx?
Nginx has no per-directory config, so it goes in the server block. This writes both blocks: one that redirects, one that serves the site.
Will this break my SSL certificate?
No, though the certificate has to cover both names. Most free certificates include the bare domain and www automatically.
Can the redirect stand in for a canonical tag?
No. A redirect settles the request before the page loads, and a canonical tag settles what the page says about itself. Sites need both, pointing the same way.
Do existing links to the other version still work?
Old links still land, via the 301. Search engines follow it and consolidate the signals onto the host you picked, which is the whole point of doing it once.
Where does the domain I type into Denwix go?
No. Your browser writes the rules, and this site never fetches your domain or writes it to a log.
Tools For Redirects
A canonical host is one rule. These three cover what comes after it.
- .htaccess Redirect Generator
Page-level 301s and 302s, written the same way.
- Redirect Chain Checker
Confirm every address lands in a single hop.
- SSL Checker
Make sure the certificate lists both host names.
Ready To Settle Your Host?
Type the domain, pick the winner, and check the four lines before you paste. The generator is free, needs no account, and writes everything in your browser.