How to redirect non-www to www URL in WordPress?

To redirect non-www to www URLs in WordPress, you have several reliable methods. Here’s a comprehensive guide:

Method 1: Using .htaccess (Recommended for Apache Servers)
Access your website files via FTP/cPanel or SSH.

Locate the .htaccess file in your root directory (usually /public_html/).

Add this code above the WordPress rules (look for # BEGIN WordPress):

apache
RewriteEngine On
RewriteCond %{HTTP_HOST} ^yourdomain.com [NC]
RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [L,R=301]
Replace yourdomain.com with your actual domain.

Save and upload the file.

Method 2: Using a Plugin (Easiest)
Install “Redirection” or “Really Simple SSL” (both handle redirects).

Go to Tools → Redirection.

Add a new redirect:

Source URL: ^/(.*)

Target URL: http://www.yourdomain.com/$1

Type: 301 (Permanent)

Method 3: In WordPress Settings
Go to Settings → General.

Ensure both WordPress Address (URL) and Site Address (URL) start with www.

Save changes (may not force redirects for existing links—use with Method 1 or 2).

Method 4: For Nginx Servers
Edit your Nginx config file (usually /etc/nginx/sites-available/yourdomain.com):

nginx
server {
listen 80;
server_name yourdomain.com;
return 301 http://www.yourdomain.com$request_uri;
}
Restart Nginx:

bash
sudo systemctl restart nginx
Verify the Redirect
Visit http://yourdomain.com in a browser.

It should automatically change to http://www.yourdomain.com.

Check with a tool like Redirect Checker.

Why Use www?
SEO Benefits: Consistent URLs prevent duplicate content issues.

Cookie Handling: www can reduce cookie overhead for static subdomains (e.g., cdn.yourdomain.com).

Note: Replace http:// with https:// if you use SSL (recommended). For HTTPS, use:

apache
RewriteRule ^(.*)$ https://www.yourdomain.com/$1 [L,R=301]

 

 

non-www redirects not working

If your non-www to www redirects aren’t working, here’s a step-by-step troubleshooting guide:

1. Verify Your Redirect Code
For Apache (.htaccess):
apache
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [L,R=301]
Replace example.com with your actual domain

Must be placed before the WordPress rules

For IIS (web.config):
xml
<rule name=”Redirect to www” stopProcessing=”true”>
<match url=”(.*)” />
<conditions>
<add input=”{HTTP_HOST}” pattern=”^example\.com$” />
</conditions>
<action type=”Redirect” url=”https://www.example.com/{R:1}” redirectType=”Permanent” />
</rule>
2. Common Reasons for Failure
Caching Issues
Clear:

Browser cache (test in Incognito mode)

WordPress cache (if using plugins like WP Rocket)

Server/CDN cache (Cloudflare, Varnish, etc.)

SSL Certificate Problems
Ensure your cert covers both versions:
openssl s_client -connect example.com:443 -servername example.com | openssl x509 -noout -text

WordPress Settings Override
Check:
Settings → General → WordPress Address & Site Address
Must match your preferred version (www or non-www)

Plugin Conflicts
Temporarily disable all plugins (especially SEO/cache plugins)

3. Debugging Steps
Test with curl (bypasses browser cache):

bash
curl -I http://example.com
Look for 301 Moved Permanently and Location: https://www.example.com

Check redirect chain with:

Redirect Checker

Chrome DevTools → Network tab (check “Preserve log”)

Server Configuration

Apache: Ensure mod_rewrite is enabled (sudo a2enmod rewrite)

IIS: Verify URL Rewrite Module is installed

.htaccess Overrides
Confirm Apache allows overrides:

apache
<Directory /var/www/html>
AllowOverride All
</Directory>
4. Alternative Solutions
Force via WordPress (wp-config.php):
php
define(‘WP_HOME’, ‘https://www.example.com’);
define(‘WP_SITEURL’, ‘https://www.example.com’);
PHP Redirect (last resort):
Add this to your theme’s header.php (before <!DOCTYPE html>):

php
if ($_SERVER[‘HTTP_HOST’] === ‘example.com’) {
header(“HTTP/1.1 301 Moved Permanently”);
header(“Location: https://www.example.com” . $_SERVER[‘REQUEST_URI’]);
exit();
}
5. Final Checks
Update Google Search Console & Analytics to use your preferred version

Ensure all hardcoded links in content use the canonical URL

Check for mixed content warnings (HTTPS issues)

If it still fails, share:

Your current .htaccess/web.config

Server type (Apache/Nginx/IIS)

Any caching/CDN in use

Exact behavior you’re seeing

 

 

Redirect non www to www Apache

To properly redirect non-www to www on an Apache server, follow these steps:

1. Edit your .htaccess file
Add this code at the top of your .htaccess file (before any WordPress rules):

apache
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [L,R=301]
Replace example.com with your actual domain.

2. Key components explained:
RewriteEngine On – Enables the rewriting engine

RewriteCond – Checks if the domain matches the non-www version

NC – Makes the match case-insensitive

R=301 – Permanent redirect (good for SEO)

L – Last rule (stop processing further rules)

3. For both HTTP and HTTPS:
apache
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [L,R=301]
4. Additional recommendations:
Clear all caches (browser, WordPress, server)

Verify it works using:

bash
curl -I http://example.com
Should show:

HTTP/1.1 301 Moved Permanently
Location: https://www.example.com/
Check WordPress settings:

Settings → General → Ensure both URLs use www version

5. Troubleshooting:
Make sure mod_rewrite is enabled:

bash
sudo a2enmod rewrite
sudo systemctl restart apache2
Verify .htaccess is being read:

apache
<Directory /var/www/html>
AllowOverride All
</Directory>
Check for conflicting rules in other .htaccess files

6. Complete WordPress-ready example:
apache
# BEGIN WWW Redirect
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [L,R=301]
# END WWW Redirect

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^index\.php$ – [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Remember to:

Test in incognito mode

Check for plugin conflicts

Verify your SSL certificate covers both versions

 

 

Cloudflare redirect non www to www

Redirecting non-www to www using Cloudflare
There are several ways to set up a non-www to www redirect when using Cloudflare. Here are the best methods:

Method 1: Cloudflare Page Rules (Recommended)
Log in to your Cloudflare dashboard

Go to Rules > Page Rules

Create a new page rule with these settings:

URL pattern: example.com/*

Setting: Forwarding URL

Status code: 301 – Permanent Redirect

Destination URL: https://www.example.com/$1

Add another rule for the root domain:

URL pattern: example.com

Same settings as above

Method 2: Using Cloudflare Workers (Advanced)
For more control, create a Worker:

javascript
addEventListener(‘fetch’, event => {
event.respondWith(handleRequest(event.request))
})

async function handleRequest(request) {
const url = new URL(request.url)
if (url.hostname === ‘example.com’) {
url.hostname = ‘www.example.com’
return Response.redirect(url.toString(), 301)
}
return fetch(request)
}
Then add a route in Workers for example.com/*

Method 3: Combined with .htaccess (Server-Level)
If you want server-level redirects alongside Cloudflare:

apache
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [L,R=301]
Important Notes:
SSL/TLS Settings:

Set your SSL/TLS mode to Full or Full (Strict)

Ensure you have a valid SSL certificate covering both versions

DNS Settings:

Both www and root domain should be proxied (orange cloud icon)

Root domain must use an A record

www can use either A or CNAME record

Cache Considerations:

Clear Cloudflare cache after making changes

Browser-level testing should use incognito mode

WordPress Specifics:

Update WordPress Address in Settings → General

Check for plugin conflicts (especially caching plugins)

Verification:
Test your redirect with:

bash
curl -I http://example.com
Should return:

HTTP/2 301
location: https://www.example.com/

 

 

 

Redirect www to non www cPanel

Redirecting www to non-www in cPanel
There are several ways to set up a www to non-www redirect in cPanel. Here are the most effective methods:

Method 1: Using cPanel’s Redirect Tool (Easiest)
Log in to your cPanel account

Under “Domains” section, click “Redirects”

Set up the redirect:

Type: Permanent (301)

https?: Select your preferred protocol

www.redirection: Redirect “www.domain.com” to “domain.com”

Wild Card Redirect: Check this box to redirect all pages

Click “Add”

Method 2: Manual .htaccess Method (More Control)
Access your website files via File Manager or FTP

Edit or create the .htaccess file in your public_html folder

Add these rules at the top (before any WordPress rules):

apache
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.example\.com [NC]
RewriteRule ^(.*)$ https://example.com/$1 [L,R=301]
Replace “example.com” with your actual domain.

Method 3: For WordPress Sites
In addition to the .htaccess method above:

Go to WordPress Dashboard → Settings → General

Update both URLs to use the non-www version:

WordPress Address (URL): https://example.com

Site Address (URL): https://example.com

Save changes

Important Notes:
SSL Certificate: Ensure your SSL certificate covers both www and non-www versions

Cache: Clear all caches after making changes:

Browser cache

WordPress cache (if using caching plugins)

cPanel cache (if applicable)

Testing: Verify with:

bash
curl -I https://www.example.com
Should return 301 redirect to non-www version

Troubleshooting:
If redirects aren’t working:

Check that mod_rewrite is enabled

Verify .htaccess is being read by Apache

Ensure no conflicting redirects exist

Check for typos in your domain name

 

 

www Versus non-www Domains

www vs. non-www Domains: The Complete Guide
Technical Differences
www (Subdomain)
Technically a subdomain (www.example.com)

Allows CNAME records (useful for CDNs and load balancing)

Cookies are restricted to www only (not sent to other subdomains)

Better for large-scale sites with multiple services

non-www (Root Domain)
The “naked” domain (example.com)

Requires A/AAAA records (can’t use CNAME at root level)

Cookies are sent to all subdomains

Simpler, shorter URLs

SEO Considerations
No inherent SEO advantage – Google treats both equally when properly configured

Must choose one as canonical to avoid duplicate content issues

301 redirects are essential to consolidate link equity

Consistency matters across:

Internal links

Sitemaps

Backlinks

Social shares

Performance Impact
Negligible difference in load times

www may have slight advantage when using CDNs

Cookie handling can affect performance (non-www sends cookies to all subdomains)

Best Practices
Pick one version and stick with it permanently

Implement 301 redirects from non-preferred version

Set canonical URLs in:

WordPress settings (for CMS sites)

HTML headers

Sitemaps

Configure SSL certificates to cover both versions

Register both versions in Google Search Console

When to Choose www
If using multiple subdomains (blog., shop., etc.)

For large-scale sites needing CNAME flexibility

When using enterprise CDN solutions

If your audience expects traditional www URLs

When to Choose non-www
For simpler, cleaner branding

Small to medium websites

When you want shorter URLs

Modern web projects where www feels outdated

Implementation Examples
For www preference:
apache
# .htaccess
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [L,R=301]
For non-www preference:
apache
# .htaccess
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.example\.com [NC]
RewriteRule ^(.*)$ https://example.com/$1 [L,R=301]
Critical Checks After Implementation
Verify redirects work in incognito mode

Check SSL certificate covers both versions

Update all hardcoded internal links

Submit preferred version to search engines

Monitor for mixed content warnings

Remember: The choice matters less than consistent implementation. Both options are equally valid when properly configured.

 

 

Fixing non-www redirection

Here’s a comprehensive guide to fixing non-www to www redirection issues:

1. Verify Current Setup
First check if your domain has any existing redirects:

bash
curl -I http://yourdomain.com
curl -I https://yourdomain.com
Look for “301 Moved Permanently” responses.

2. Server-Level Solutions
For Apache (.htaccess):

apache
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^yourdomain\.com [NC]
RewriteRule ^(.*)$ https://www.yourdomain.com/$1 [L,R=301]
</IfModule>
For NGINX:

nginx
server {
listen 80;
server_name yourdomain.com;
return 301 https://www.yourdomain.com$request_uri;
}
For IIS (web.config):

xml
<rule name=”Redirect to www” stopProcessing=”true”>
<match url=”(.*)” />
<conditions>
<add input=”{HTTP_HOST}” pattern=”^yourdomain\.com$” />
</conditions>
<action type=”Redirect” url=”https://www.yourdomain.com/{R:1}” redirectType=”Permanent” />
</rule>
3. Platform-Specific Fixes
WordPress:

Update Settings → General → WordPress/Site Address to use www

Add to wp-config.php:

php
define(‘WP_HOME’,’https://www.yourdomain.com’);
define(‘WP_SITEURL’,’https://www.yourdomain.com’);
Cloudflare:

Create Page Rule:

Pattern: yourdomain.com/*

Setting: Forwarding URL (301)

Destination: https://www.yourdomain.com/$1

4. DNS Configuration
Ensure both records exist:

A record for @ → server IP

CNAME for www → yourdomain.com

All records should be proxied (orange cloud) if using Cloudflare

5. SSL Certificate
Must cover both versions (or use wildcard)

Check with:

bash
openssl s_client -connect yourdomain.com:443 | openssl x509 -text | grep DNS
6. Testing & Validation
Test all variations:

bash
curl -L http://yourdomain.com # Should follow to https www
curl -L https://yourdomain.com # Should follow to https www
curl -L http://www.yourdomain.com # Should follow to https www
Check redirect chain with browser DevTools (Network tab)

7. Common Issues & Fixes
Problem: Redirect loops

Solution: Check conflicting rules in .htaccess/web.config

Ensure WordPress settings match final destination

Problem: SSL errors

Solution: Install certificate for both versions

Use SSL checker tools

Problem: Caching interference

Clear:

Browser cache

Server cache (OPcache, Redis)

CDN cache (Cloudflare)

Problem: Mixed content

Update all hardcoded URLs in database:

sql
UPDATE wp_options SET option_value = replace(option_value, ‘http://yourdomain.com’, ‘https://www.yourdomain.com’);
UPDATE wp_posts SET post_content = replace(post_content, ‘http://yourdomain.com’, ‘https://www.yourdomain.com’);
8. Final Checks
Update Google Search Console property

Submit new sitemap with preferred URLs

Monitor for 404 errors in analytics

Check canonical tags sitewide

 

 

Stop wordpress redirecting www to non-www

How to Stop WordPress from Redirecting www to non-www
If your WordPress site is automatically redirecting www to non-www (or vice versa) against your wishes, here’s how to fix it:

1. Check WordPress Settings
First verify your WordPress address settings:

Go to Settings → General in your WordPress admin

Ensure both fields show your preferred version (with or without www):

WordPress Address (URL)

Site Address (URL)

Click “Save Changes” even if they appear correct

2. Fix the .htaccess File
Remove or modify any existing redirect rules in your .htaccess file (found in your root directory):

To remove www → non-www redirect:
apache
# Remove any rules that look like this:
RewriteCond %{HTTP_HOST} ^www\.example\.com [NC]
RewriteRule ^(.*)$ https://example.com/$1 [L,R=301]
To enforce non-www → www (if needed):
apache
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [L,R=301]
3. Check wp-config.php
Look for and remove/update these lines if present:

php
define(‘WP_HOME’,’https://example.com’); // Remove or add www
define(‘WP_SITEURL’,’https://example.com’); // Remove or add www
4. Disable Plugin-Related Redirects
Some plugins can force redirects:

Temporarily disable all plugins

Check if redirect stops

Reactivate plugins one by one to find the culprit

Common offenders: SEO plugins, caching plugins, security plugins

5. Check Theme Functions
Some themes add redirects in functions.php:

Check your theme’s functions.php for:

php
wp_redirect()
or

php
add_filter(‘template_redirect’, …)
Remove any forced redirect code

6. Clear All Caches
Clear:

WordPress cache (if using caching plugins)

Browser cache

Server cache (OPcache, Redis, etc.)

CDN cache (Cloudflare, etc.)

7. Verify After Changes
Test with:

bash
curl -I https://www.example.com
Should return 200 OK (not 301 redirect) if you want to keep www version.

8. Database Check (Advanced)
If redirects persist, check these database options:

sql
SELECT * FROM wp_options WHERE option_name IN (‘home’,’siteurl’);
Update if needed:

sql
UPDATE wp_options SET option_value = ‘https://www.example.com’ WHERE option_name IN (‘home’,’siteurl’);
9. Server Configuration
For persistent issues, check:

Apache/Nginx virtual host files

Server-level redirects

Cloudflare Page Rules

 

 

not redirecting to www version in wordpress chrome

If your WordPress site isn’t redirecting to the www version in Chrome specifically, follow these troubleshooting steps:

1. Check WordPress URL Settings
Go to Settings → General in your WordPress dashboard.

Ensure both fields use the www version:

WordPress Address (URL): https://www.yourdomain.com

Site Address (URL): https://www.yourdomain.com

Save Changes (even if they look correct).

2. Clear Chrome Cache & Test in Incognito
Chrome aggressively caches redirects.
✅ Test in Incognito Mode (Ctrl+Shift+N) or:
✅ Hard Refresh (Ctrl+Shift+R)
✅ Clear Chrome Cache:

Open chrome://settings/clearBrowserData

Check “Cached images and files” → Clear data.

3. Force Redirect via .htaccess (Apache)
Add this to your .htaccess file (before WordPress rules):

apache
RewriteEngine On
RewriteCond %{HTTP_HOST} ^yourdomain\.com [NC]
RewriteRule ^(.*)$ https://www.yourdomain.com/$1 [L,R=301]
Replace yourdomain.com with your actual domain.

Save and test again.

4. Disable Plugins Temporarily
A plugin (e.g., SEO, caching, security) might override redirects.

Go to Plugins → Installed Plugins.

Disable all plugins.

Test if the redirect works.

Re-enable plugins one by one to find the culprit.

5. Check wp-config.php for Overrides
Look for these lines and add/update the www version:

php
define(‘WP_HOME’, ‘https://www.yourdomain.com’);
define(‘WP_SITEURL’, ‘https://www.yourdomain.com’);
Place this before /* That’s all, stop editing! */.

6. Verify SSL & HTTPS Settings
Ensure your SSL certificate covers both versions:

yourdomain.com

www.yourdomain.com

In Settings → General, confirm URLs start with https://www.

If using Cloudflare:

Set SSL/TLS mode to Full (Strict).

Disable “Automatic HTTPS Rewrites” (temporarily for testing).

7. Test with curl (Bypass Chrome Cache)
Run in Terminal/PowerShell:

bash
curl -I http://yourdomain.com
Expected output:

HTTP/1.1 301 Moved Permanently
Location: https://www.yourdomain.com/
If not, the issue is server-side (not Chrome-specific).

8. Check for Conflicting Code
Theme’s functions.php: Look for wp_redirect() or URL filters.

Database: Run this SQL query (via phpMyAdmin):

sql
SELECT * FROM wp_options WHERE option_name IN (‘home’, ‘siteurl’);
Ensure both values use https://www.yourdomain.com.

9. Cloudflare or CDN Conflicts
If using Cloudflare:

Go to Rules → Page Rules.

Delete any conflicting rules forcing non-www.

Create a new rule:

URL Pattern: yourdomain.com/*

Setting: Forwarding URL (301) → https://www.yourdomain.com/$1.

10. Final Checks
Update all internal links to use www.

Submit to Google Search Console (www version as canonical).

Check Chrome extensions (disable temporarily).

Still Not Working?
Server logs: Check Apache/Nginx error logs.

Hosting support: Some hosts enforce redirects (e.g., SiteGround’s “Force HTTPS” tool).

 

 

WordPress redirect non www to www

Here’s the complete guide to properly redirect non-www to www in WordPress:

1. Update WordPress Settings (Essential First Step)
Go to Settings → General

Set both URLs to use www:

WordPress Address (URL): https://www.yourdomain.com

Site Address (URL): https://www.yourdomain.com

Click “Save Changes”

2. .htaccess Method (Most Reliable)
Edit your .htaccess file (in root folder) and add this before WordPress rules:

apache
# BEGIN Force www
RewriteEngine On
RewriteCond %{HTTP_HOST} ^yourdomain\.com [NC]
RewriteRule ^(.*)$ https://www.yourdomain.com/$1 [L,R=301]
# END Force www
3. wp-config.php Method (Alternative)
Add this before “That’s all, stop editing”:

php
define(‘WP_HOME’, ‘https://www.yourdomain.com’);
define(‘WP_SITEURL’, ‘https://www.yourdomain.com’);
4. Plugin Method (Simplest)
Install a redirection plugin like:

Really Simple SSL

Redirection

WP Force SSL & HTTPS Redirect

Configure to force www and HTTPS.

5. Cloudflare Users
Create a Page Rule:

Pattern: yourdomain.com/*
Setting: Forwarding URL (301)
Destination: https://www.yourdomain.com/$1
Critical Checks:
SSL Certificate: Must cover both versions

Test with curl:

bash
curl -I http://yourdomain.com
Should show:

HTTP/1.1 301 Moved Permanently
Location: https://www.yourdomain.com/
Clear all caches:

WordPress cache

Browser cache (test in Incognito)

CDN cache (if using Cloudflare)

Troubleshooting:
If redirect loops occur: Ensure no conflicting rules exist

If HTTPS breaks: Update all URLs to https://www

If plugins interfere: Temporarily disable caching/SEO plugins

Database Update (For Stubborn Cases)
Run these SQL queries via phpMyAdmin:

sql
UPDATE wp_options SET option_value = ‘https://www.yourdomain.com’ WHERE option_name IN (‘home’, ‘siteurl’);
UPDATE wp_posts SET post_content = REPLACE(post_content, ‘https://yourdomain.com’, ‘https://www.yourdomain.com’);
This comprehensive approach ensures all visitors and search engines are properly redirected to your www version.

 

 

Redirect non www to www WordPress plugin

If you prefer using a WordPress plugin to redirect non-www to www URLs, here are the best options and how to implement them:

Best WordPress Plugins for Non-WWW to WWW Redirection
1. Really Simple SSL (Recommended)
Handles both HTTPS and www redirects automatically

Setup:

Install & activate from WordPress plugins directory

Go to Settings → SSL

Enable “Enable 301 .htaccess redirect” (forces HTTPS)

Ensure your WordPress URLs in Settings → General include www

2. Redirection
Advanced control over redirects

Setup:

Install & activate plugin

Go to Tools → Redirection

Add new redirect:

Source URL: ^/(.*)

Target URL: https://www.yourdomain.com/$1

Regex: Enabled

Type: 301 Permanent

3. WP Force SSL & HTTPS Redirect
Simple dedicated solution

Setup:

Install & activate

Go to Settings → WP Force SSL

Check:

“Force SSL”

“Force WWW”

Save changes

4. All In One SEO (AIOSEO)
For sites already using this SEO plugin

Setup:

Go to All in One SEO → General Settings

Under “Canonical URL”, set:
https://www.yourdomain.com

Enable “Redirect Attachments to Parent Post”

Important Additional Steps
Update WordPress URLs:

Settings → General → Set both URLs to www version

Clear Caches:

WordPress cache (if using caching plugin)

Browser cache (test in incognito)

CDN cache (if using Cloudflare)

Verify SSL Certificate:

Must cover both www and non-www versions

Test Your Setup:

bash
curl -I http://yourdomain.com
Should return:

HTTP/1.1 301 Moved Permanently
Location: https://www.yourdomain.com/
Why Use a Plugin Instead of .htaccess?
No coding required

Easy to undo changes

Visual interface

Additional features (like SSL handling)

Works on all server types (including IIS)

Troubleshooting Plugin Issues
If redirects don’t work:

Check for conflicting plugins (especially caching plugins)

Ensure no manual redirects exist in .htaccess

Verify your hosting doesn’t override redirects

Check WordPress Address in Settings → General

 

 

 

WordPress Multisite redirect non www to www

Redirecting Non-WWW to WWW in WordPress Multisite
For WordPress Multisite installations, redirecting non-www to www requires special considerations due to the network architecture. Here’s how to properly implement this:

Method 1: Using .htaccess (Recommended for Multisite)
Add these rules to your .htaccess file before the WordPress multisite rules:

apache
# BEGIN Non-WWW to WWW Redirect
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(?:www\.)?(yourdomain\.com)$ [NC]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ https://www.%1%{REQUEST_URI} [L,R=301]
# END Non-WWW to WWW Redirect
Method 2: Network-Wide Plugin Solution
Install and activate WP Force SSL & HTTPS Redirect network-wide

Network Admin → Settings → WP Force SSL

Enable:

“Force SSL”

“Force WWW”

“Network Wide Settings”

Method 3: Multisite Constants (wp-config.php)
Add these to your wp-config.php before “That’s all, stop editing”:

php
/* Multisite WWW Redirect */
define(‘DOMAIN_CURRENT_SITE’, ‘www.yourdomain.com’);
define(‘COOKIE_DOMAIN’, ‘www.yourdomain.com’);
define(‘ADMIN_COOKIE_PATH’, ‘/’);
Method 4: For Nginx Servers
Add this to your server block:

nginx
server {
server_name yourdomain.com;
return 301 https://www.yourdomain.com$request_uri;
}
Critical Multisite-Specific Considerations
Database Tables:

Check wp_blogs and wp_site tables for correct domain entries

Run this SQL query:

sql
UPDATE wp_site SET domain = ‘www.yourdomain.com’ WHERE id = 1;
UPDATE wp_blogs SET domain = REPLACE(domain, ‘yourdomain.com’, ‘www.yourdomain.com’);
Uploads Path:

Verify wp_upload_dir() URLs in subsites don’t hardcode non-www

Domain Mapping:

If using domain mapping plugins, update all mappings to use www

Caching:

Clear object cache network-wide

Purge CDN cache for all subsites

Verification Steps
Test all site variations:

bash
curl -I http://yourdomain.com
curl -I https://yourdomain.com
curl -I http://www.yourdomain.com
Check subsite redirects:

bash
curl -I http://subsite.yourdomain.com
Verify cookies are set correctly for www domain

Troubleshooting Multisite Issues
If redirects fail:

Check for conflicting plugins network-wide

Verify no individual subsite overrides the redirect

Ensure your SSL certificate covers:

*.yourdomain.com (wildcard)

yourdomain.com

www.yourdomain.com

Check server error logs for rewrite rule conflicts

 

 

Www to non www redirect htaccess

Here’s how to redirect www to non-www URLs using .htaccess:

Basic Redirect (HTTP & HTTPS)
apache
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [L,R=301]
Works for both http://www.example.com → https://example.com

Preserves the requested path (/page, /post, etc.)

NC = Case-insensitive match

R=301 = Permanent SEO-friendly redirect

HTTP → HTTPS + Remove WWW (Recommended)
apache
RewriteEngine On
# Force HTTPS first
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# Remove www
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [L,R=301]
Combines HTTPS enforcement + www removal

Example:
http://www.example.com/page → https://example.com/page

WordPress-Specific Rules
Place this before WordPress’ default rules:

apache
# BEGIN Remove www
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [L,R=301]
# END Remove www

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^index\.php$ – [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Testing & Validation
Verify with curl:

bash
curl -I http://www.example.com
Should return:

HTTP/1.1 301 Moved Permanently
Location: https://example.com/
Check in Chrome DevTools (Network tab):

Look for 301 status on initial request.

Troubleshooting
Redirect loops?

Ensure no conflicting rules exist in .htaccess.

Check WordPress settings (Settings → General) for correct URLs.

Not working?

Confirm mod_rewrite is enabled (Apache).

Verify .htaccess is processed (check Apache config for AllowOverride All).

Clear browser/cache/CDN (Cloudflare, etc.).

For Nginx Users
Add to server block:

nginx
server {
listen 80;
server_name www.example.com;
return 301 https://example.com$request_uri;
}

 

 

 

 

 

 

Frequently Asked Questions (FAQ’s)
………………………………..
non www version not redirecting to www version in wordpress solution

If your non-www version isn’t redirecting to the www version in WordPress, here’s a step-by-step troubleshooting guide with solutions:

1. Check WordPress Settings
Go to Settings → General

Ensure both fields use the www version:

WordPress Address (URL): https://www.yourdomain.com

Site Address (URL): https://www.yourdomain.com

Save Changes (even if they’re already correct).

2. Force Redirect via .htaccess (Apache Servers)
Access your site’s root folder via FTP/cPanel/SSH.

Open the .htaccess file (hidden—enable “Show Hidden Files” if needed).

Add this code above the # BEGIN WordPress line:

apache
RewriteEngine On
RewriteCond %{HTTP_HOST} ^yourdomain\.com [NC]
RewriteRule ^(.*)$ https://www.yourdomain.com/$1 [L,R=301]
Replace yourdomain.com with your actual domain.

Save and upload the file.

Note: If you use HTTPS, keep https:// in the code. For HTTP-only, use http://.

3. Use a Plugin (No Coding)
Install “Redirection” or “Really Simple SSL”:

Go to Tools → Redirection → Add New.

Set up a redirect:

Source URL: ^/(.*)

Target URL: https://www.yourdomain.com/$1

Type: 301 (Permanent)

Save.

4. Nginx Server Fix
Edit your Nginx config file (/etc/nginx/sites-available/yourdomain.com):

nginx
server {
listen 80;
server_name yourdomain.com;
return 301 https://www.yourdomain.com$request_uri;
}
Then restart Nginx:

bash
sudo systemctl restart nginx
5. Clear Caches
Clear WordPress cache (if using WP Rocket, W3TC, etc.).

Clear browser cache or test in incognito mode.

Clear CDN cache (Cloudflare, StackPath, etc.).

6. Verify DNS Settings
Ensure your DNS A record points to the correct IP for both:

yourdomain.com

www.yourdomain.com

(Check via your domain registrar or hosting provider.)

7. Debug Common Issues
Mixed HTTPS/HTTP: Ensure all redirects use https:// if your site is SSL-enabled.

Plugin Conflicts: Temporarily deactivate caching/security plugins to test.

Infinite Redirects: Remove duplicate rules in .htaccess or Nginx config.

Final Test
Visit http://yourdomain.com (or https://). It should instantly redirect to https://www.yourdomain.com.
Use Redirect Checker to verify.

Still stuck? Provide:

Your .htaccess content (if using Apache).

Whether you’re on Apache/Nginx.

Any error logs (check via hosting panel).

 

 

How to Redirect Non-WWW Version to WWW Version?

To redirect the non-www version of your website to the www version, follow these methods depending on your server type:

Method 1: Using .htaccess (Apache Servers)
Connect to your server via FTP/cPanel/SSH

Locate the .htaccess file in your root directory (usually /public_html/)

Add this code above the # BEGIN WordPress line:

apache
RewriteEngine On
RewriteCond %{HTTP_HOST} ^yourdomain\.com [NC]
RewriteRule ^(.*)$ https://www.yourdomain.com/$1 [L,R=301]
Replace yourdomain.com with your actual domain

Save and upload the file

Method 2: Using WordPress Plugin (Easiest)
Install and activate the “Redirection” plugin

Go to Tools → Redirection

Add new redirect:

Source URL: ^/(.*)

Target URL: https://www.yourdomain.com/$1

Type: 301 (Permanent)

Save changes

Method 3: Nginx Server Configuration
Edit your Nginx config file (typically in /etc/nginx/sites-available/yourdomain.conf):

nginx
server {
listen 80;
server_name yourdomain.com;
return 301 https://www.yourdomain.com$request_uri;
}
Then restart Nginx:

bash
sudo systemctl restart nginx
Method 4: Through cPanel
Login to cPanel

Go to Domains → Redirects

Set:

Type: Permanent (301)

Redirects from: yourdomain.com

Redirects to: https://www.yourdomain.com

Click Add

Important Notes:
Always use https:// if your site has SSL

Clear all caches (browser, WordPress, CDN) after making changes

Test with Redirect Checker

For WordPress, ensure Settings → General has the www version in both URL fields

Troubleshooting:
If redirects aren’t working:

Check for conflicting plugins

Verify no duplicate redirect rules exist

Ensure DNS records point to the same IP for both versions

Check server error logs

Choose the method that best fits your technical comfort level. The .htaccess method (Method 1) is most reliable for Apache servers, while the plugin method (Method 2) is simplest for beginners.

 

 

How to redirect non-www to www URL in WordPress?

To redirect non-www URLs to www URLs in WordPress, you have several reliable options. Here’s a comprehensive guide with the most effective methods:

1. Using .htaccess (Best for Apache servers)
Access your website files via FTP or cPanel File Manager

Locate the .htaccess file in your root directory (usually public_html)

Add this code ABOVE the WordPress rules (before # BEGIN WordPress):

apache
RewriteEngine On
RewriteCond %{HTTP_HOST} ^yourdomain\.com [NC]
RewriteRule ^(.*)$ https://www.yourdomain.com/$1 [L,R=301]
Replace “yourdomain.com” with your actual domain

Save the file

2. Using a WordPress Plugin (Easiest method)
Install and activate the “Redirection” plugin

Go to Tools → Redirection

Click “Add New”

Set up the redirect:

Source URL: ^/(.*)

Target URL: https://www.yourdomain.com/$1

Select “Regex” and “301 (Permanent)”

Save the redirect

3. Through WordPress Settings
Go to Settings → General

Make sure both URLs use the www version:

WordPress Address (URL)

Site Address (URL)

Save changes

4. For Nginx Servers
Edit your Nginx configuration file (usually in /etc/nginx/sites-available/):

nginx
server {
listen 80;
server_name yourdomain.com;
return 301 https://www.yourdomain.com$request_uri;
}
Then restart Nginx:

bash
sudo systemctl restart nginx
Important Notes:
Always use HTTPS if your site has SSL (replace http:// with https:// in all examples)

Clear all caches after making changes

Test with a redirect checker tool

For WordPress multisite, use the network admin settings

Verification:
After implementing, test by:

Visiting http://yourdomain.com (should redirect to https://www.yourdomain.com)

Using an online redirect checker tool

Checking your browser’s developer tools (Network tab)

If the redirect isn’t working:

Double-check for typos in the code

Ensure no conflicting redirects exist

Check your server error logs

Temporarily disable caching plugins

Choose the method that best fits your technical comfort level. The .htaccess method is most reliable for Apache servers, while the plugin method is simplest for beginners.

 

How to redirect non-www to www in web config?

To redirect non-www URLs to www URLs using web.config (for IIS/Windows servers), follow these steps:

Method: Using web.config (IIS Server)
Locate or create the web.config file in your website’s root directory (typically where your WordPress files are installed).

Add or modify the <rewrite> rules inside <system.webServer>:

xml
<?xml version=”1.0″ encoding=”UTF-8″?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<!– Redirect non-www to www (HTTP & HTTPS) –>
<rule name=”Redirect non-www to www” stopProcessing=”true”>
<match url=”(.*)” />
<conditions>
<add input=”{HTTP_HOST}” pattern=”^yourdomain\.com$” />
</conditions>
<action type=”Redirect” url=”https://www.yourdomain.com/{R:1}” redirectType=”Permanent” />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Replace yourdomain.com with your actual domain (e.g., example.com).

For HTTPS-only, keep https://.

For HTTP-only, change to http://.

Save the file and test the redirect by visiting:

http://yourdomain.com → Should redirect to https://www.yourdomain.com.

Key Notes
✅ Works for:

IIS servers (Windows hosting).

WordPress or any other website running on IIS.

🚨 Troubleshooting:

No redirect? Ensure the URL Rewrite Module is installed in IIS.

Mixed content errors? Use https:// consistently.

Test tools: Use Redirect Checker to verify.

Alternative: WordPress Plugin (If IIS settings are restricted)
Install the “Redirection” plugin.

Go to Tools → Redirection and add a rule:

Source URL: ^/(.*)

Target URL: https://www.yourdomain.com/$1

Regex: Enabled | Type: 301 Permanent.

Why Use This?
SEO-Friendly: Avoids duplicate content (non-www vs. www).

User Experience: Ensures consistent URLs.

 

 

 

How do I enable www in WordPress?

To enable www in WordPress (e.g., force https://example.com → https://www.example.com), follow these steps:

Method 1: Update WordPress Settings (Quickest)
Go to Settings → General in your WordPress dashboard.

Update both URLs to include www:

WordPress Address (URL): https://www.yourdomain.com

Site Address (URL): https://www.yourdomain.com

Click Save Changes.

⚠️ Note: This alone won’t force redirects for existing links. Pair with Method 2 or 3 below.

Method 2: Redirect via .htaccess (Apache/Linux Servers)
Access your site’s root folder via FTP/cPanel/File Manager.

Edit the .htaccess file (before # BEGIN WordPress):

apache
RewriteEngine On
RewriteCond %{HTTP_HOST} ^yourdomain\.com [NC]
RewriteRule ^(.*)$ https://www.yourdomain.com/$1 [L,R=301]
Replace yourdomain.com with your actual domain.

Save the file.
🔹 Test: Visit http://yourdomain.com → Should redirect to https://www.yourdomain.com.

Method 3: Use a Plugin (No Coding)
Install “Redirection” or “Really Simple SSL”.

For Redirection:

Go to Tools → Redirection → Add New.

Source URL: ^/(.*)

Target URL: https://www.yourdomain.com/$1

Regex: Checked | Type: 301 Permanent.

Method 4: For Nginx Servers
Edit your Nginx config file (/etc/nginx/sites-available/yourdomain.conf):

nginx
server {
listen 80;
server_name yourdomain.com;
return 301 https://www.yourdomain.com$request_uri;
}
Restart Nginx:

bash
sudo systemctl restart nginx
Method 5: Via cPanel (If Available)
Go to Domains → Redirects.

Set:

Type: Permanent (301)

Redirects from: yourdomain.com

Redirects to: https://www.yourdomain.com

Click Add.

Verify & Fix Common Issues
Test the Redirect:

Visit http://yourdomain.com → Should auto-redirect to https://www.yourdomain.com.

Use Redirect Checker.

Clear Caches:

WordPress cache (if using plugins like WP Rocket).

Browser cache (Ctrl+F5 or incognito mode).

HTTPS? Ensure your SSL certificate covers both yourdomain.com and www.yourdomain.com (use SSL Checker).

Why Use www?
SEO: Avoids duplicate content (non-www vs. www).

Cookies: Reduces overhead for subdomains (e.g., cdn.yourdomain.com).

Branding: Looks more professional in some industries.

 

 

Should you redirect non-www to www?

Whether you should redirect non-www to www (or vice versa) depends on your needs, but here are the key considerations to help you decide:

1. SEO Implications
Avoids Duplicate Content:
Search engines may treat example.com and www.example.com as separate sites, splitting your SEO authority. A 301 redirect consolidates rankings.

Consistent Backlinks:
Ensures all links point to one canonical version (www or non-www), preserving link equity.

2. Technical Considerations
Cookies & Performance:

www isolates cookies from subdomains (e.g., cdn.example.com), reducing request overhead.

non-www is slightly shorter (minor UX benefit).

DNS Flexibility:
www allows easier CNAME records for CDNs or third-party services (non-www typically requires A records).

3. Branding & User Trust
www may appear more “traditional” for certain industries (e.g., finance).

non-www feels minimalist (common with startups/tech brands).

4. Best Practices
Pick one and stick with it (don’t allow both versions).

Use HTTPS regardless of your choice.

Set a canonical URL in Google Search Console.

How to Decide?
Choose www if:

You use subdomains (e.g., blog.example.com).

You prioritize technical scalability.

Choose non-www if:

You want shorter URLs.

Your brand aligns with simplicity (e.g., example.com).

Implementation
Whichever you choose:

Set a 301 redirect (via .htaccess, Nginx, or plugin).

Update WordPress URLs (Settings → General).

Verify in Google Search Console.

Example Redirects:

Non-www → www:

apache
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [L,R=301]
www → non-www:

apache
RewriteCond %{HTTP_HOST} ^www\.example\.com [NC]
RewriteRule ^(.*)$ https://example.com/$1 [L,R=301]
Final Recommendation
For most users, redirecting non-www to www is preferable due to technical flexibility. However, if simplicity is key, non-www works too—just be consistent!

 

How to redirect non-www to www on my WordPress website?

To redirect non-www to www on your WordPress website, follow these steps:

Method 1: Using .htaccess (Best for Apache/Linux Servers)
Access your website files via FTP (FileZilla) or cPanel File Manager.

Locate the .htaccess file in your root folder (usually /public_html/).

Add this code above the # BEGIN WordPress line:

apache
RewriteEngine On
RewriteCond %{HTTP_HOST} ^yourdomain\.com [NC]
RewriteRule ^(.*)$ https://www.yourdomain.com/$1 [L,R=301]
Replace yourdomain.com with your actual domain.

Save the file.

✅ Test: Visit http://yourdomain.com → It should redirect to https://www.yourdomain.com.

Method 2: Using a Plugin (Easiest)
Install the Redirection plugin.

Go to Tools → Redirection → Add New.

Set up the redirect:

Source URL: ^/(.*)

Target URL: https://www.yourdomain.com/$1

Regex: Checked

Type: 301 (Permanent)

Click Save.

Method 3: Update WordPress Settings
Go to Settings → General.

Ensure both URLs use www:

WordPress Address (URL): https://www.yourdomain.com

Site Address (URL): https://www.yourdomain.com

Save Changes.

⚠️ Note: This alone won’t force redirects—combine with Method 1 or 2.

Method 4: For Nginx Servers
Edit your Nginx config file (usually /etc/nginx/sites-available/yourdomain.conf):

nginx
server {
listen 80;
server_name yourdomain.com;
return 301 https://www.yourdomain.com$request_uri;
}
Restart Nginx:

bash
sudo systemctl restart nginx
Method 5: Via cPanel Redirects
Log in to cPanel → Domains → Redirects.

Set:

Type: Permanent (301)

Redirects from: yourdomain.com

Redirects to: https://www.yourdomain.com

Click Add.

Critical Checks After Setup
Test the Redirect:

Visit http://yourdomain.com (should redirect to https://www.yourdomain.com).

Use Redirect Checker.

Clear Caches:

WordPress cache (if using WP Rocket, W3TC, etc.).

Browser cache (Ctrl+F5 or incognito mode).

SSL Certificate:
Ensure your HTTPS certificate covers both yourdomain.com and www.yourdomain.com (use SSL Checker).

Why Choose www?
SEO: Avoids duplicate content issues.

Cookies: Isolates cookies from subdomains (e.g., cdn.yourdomain.com).

Brand Trust: Looks more professional for many industries.

 

 

How to Redirect Non-www to www URLs?

To redirect non-www URLs to www URLs, follow these methods based on your server type:

1. Using .htaccess (Apache Servers)
Access your website root via FTP/cPanel

Edit the .htaccess file (create if missing)

Add these rules above WordPress rules:

apache
RewriteEngine On
RewriteCond %{HTTP_HOST} ^yourdomain\.com [NC]
RewriteRule ^(.*)$ https://www.yourdomain.com/$1 [L,R=301]
Replace yourdomain.com with your actual domain

Save and test

2. WordPress Plugin Method
Install “Redirection” plugin

Go to Tools → Redirection

Add new redirect:

Source: ^/(.*)

Target: https://www.yourdomain.com/$1

Regex: Enabled

Type: 301 Permanent

3. Nginx Server Configuration
Edit your site config file (/etc/nginx/sites-available/yourdomain.conf):

nginx
server {
listen 80;
server_name yourdomain.com;
return 301 https://www.yourdomain.com$request_uri;
}
Then restart Nginx:

bash
sudo systemctl restart nginx
4. DNS-Level Redirect (Cloudflare)
Log in to Cloudflare

Go to Rules → Page Rules

Create new rule:

URL: yourdomain.com/*

Setting: “Forwarding URL” (301)

Destination: https://www.yourdomain.com/$1

5. WordPress Settings
Go to Settings → General

Set both URLs to use www:

WordPress Address: https://www.yourdomain.com

Site Address: https://www.yourdomain.com

Save changes

Important Notes:
Always use HTTPS in redirects if your site has SSL

Clear all caches after implementation

Test with curl or redirect checker:

bash
curl -I http://yourdomain.com
Ensure DNS records point to same IP for both versions

Troubleshooting:
If redirects don’t work:

Check server error logs

Verify no conflicting redirects exist

Temporarily disable caching plugins

Confirm .htaccess is readable by Apache

Choose the method that matches your technical comfort level and server environment. The .htaccess method works for most shared hosting, while Nginx requires server access. For WordPress-specific implementations, the plugin method is simplest.

Remember to:

Set canonical URLs in Google Search Console

Update all internal links to use www

Submit updated sitemap to search engines

 

 

How to redirect non-www to www in web config?

Redirecting non-www to www in web.config (IIS)
To redirect non-www URLs to www URLs in IIS using the web.config file, you can use the URL Rewrite module. Here’s how to do it:

Method 1: Using URL Rewrite Module
xml
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name=”Redirect non-www to www” stopProcessing=”true”>
<match url=”(.*)” />
<conditions>
<add input=”{HTTP_HOST}” pattern=”^example\.com$” />
</conditions>
<action type=”Redirect” url=”https://www.example.com/{R:1}” redirectType=”Permanent” />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Method 2: More comprehensive version (handles HTTP and HTTPS)
xml
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name=”Canonical Host Name” stopProcessing=”true”>
<match url=”(.*)” />
<conditions>
<add input=”{HTTP_HOST}” negate=”true” pattern=”^www\.example\.com$” />
<add input=”{HTTP_HOST}” negate=”true” pattern=”^localhost(:\d+)?$” />
<add input=”{HTTP_HOST}” negate=”true” pattern=”^127\.0\.0\.1(:\d+)?$” />
</conditions>
<action type=”Redirect” url=”https://www.example.com/{R:1}” redirectType=”Permanent” />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Important Notes:
Replace “example.com” with your actual domain name

For HTTPS redirects, make sure you have an SSL certificate installed

The redirectType=”Permanent” sends a 301 redirect, which is good for SEO

The second method excludes localhost and 127.0.0.1 from redirection for development purposes

Prerequisites:
IIS URL Rewrite Module must be installed on your server

The web.config file should be in the root directory of your website

 

 

How do I enable www in WordPress?
How to Enable www in WordPress
To ensure your WordPress site uses the www version of your domain (e.g., www.example.com instead of example.com), follow these steps:

Method 1: Through WordPress Settings
Log in to your WordPress admin dashboard (yourdomain.com/wp-admin)

Go to Settings → General

Update both WordPress Address (URL) and Site Address (URL) to include www:

https://www.example.com
Click “Save Changes”

Method 2: Using .htaccess (For Apache Servers)
Add this to your .htaccess file (before the WordPress rules):

apache
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [L,R=301]
</IfModule>
Method 3: Using web.config (For IIS Servers)
Add this to your web.config file:

xml
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name=”Redirect to www” stopProcessing=”true”>
<match url=”(.*)” />
<conditions>
<add input=”{HTTP_HOST}” pattern=”^example\.com$” />
</conditions>
<action type=”Redirect” url=”https://www.example.com/{R:1}” redirectType=”Permanent” />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Method 4: Using wp-config.php
Add this to your wp-config.php file (before the “That’s all, stop editing” line):

php
define(‘WP_HOME’, ‘https://www.example.com’);
define(‘WP_SITEURL’, ‘https://www.example.com’);
Important Notes:
Replace example.com with your actual domain

Clear your cache after making changes (WordPress cache, browser cache, CDN cache if you use one)

Update SSL certificates if using HTTPS to cover both www and non-www versions

Consider SEO implications – Google treats www and non-www as different sites, so pick one and stick with it

 

Should you redirect non-www to www?

Whether you should redirect non-www to www (or vice versa) depends on several factors. Here’s a detailed analysis to help you decide:

Pros of Using www (and Redirecting non-www to www)
DNS Flexibility

www allows CNAME records (useful for CDNs and load balancers), while root domains (non-www) typically require A/AAAA records.

Easier to migrate or change hosting providers.

Cookie Handling

Cookies set on example.com are sent to all subdomains (blog.example.com, shop.example.com), which can impact performance.

Using www.example.com restricts cookies to the www subdomain only.

SEO Consistency

Avoids duplicate content issues (Google treats www.example.com and example.com as separate URLs).

A 301 redirect ensures all link equity flows to your preferred version.

User Expectations

Many users still instinctively type “www” before a domain.

Pros of Using non-www (and Redirecting www to non-www)
Shorter, Cleaner URLs

example.com looks simpler than www.example.com.

Modern websites often drop www for brevity (e.g., Google, Facebook, Twitter).

Slightly Faster

Fewer bytes transmitted (though negligible impact).

Trend Toward Simplicity

Many new sites omit www as it’s no longer technically necessary.

Best Practices
Pick One and Stick With It

Use a 301 (Permanent) Redirect to enforce your choice (either www → non-www or non-www → www).

Consistency is critical for SEO and analytics.

Update All References

Set the canonical URL in WordPress (Settings → General).

Update internal links, sitemaps, and CDN/CORS settings.

Configure SSL for Both

Ensure your SSL certificate covers both example.com and www.example.com (use a wildcard cert or SAN cert).

Verify in Google Search Console

Submit your preferred version (www or non-www) as the canonical property.

When to Choose www
If you use CDNs, load balancers, or advanced DNS setups.

If you have multiple subdomains (to avoid cookie overhead).

If your audience is more traditional (expects “www”).

When to Choose non-www
For simplicity and modern branding.

If your site is small and doesn’t need complex infrastructure.

Conclusion
Redirecting non-www → www is recommended if:

You need DNS flexibility (e.g., using a CNAME for a CDN).

You have multiple subdomains and want to optimize cookies.

Redirecting www → non-www is fine if:

You prioritize shorter URLs and don’t need advanced DNS features.

Either way, enforce a redirect and stay consistent. For WordPress, the .htaccess/web.config methods above will handle this.

 

 

About Author
Digital Naka

Degital Naka is India’s best blog site for the digital marketing content. We believe in providing quality content to our readers.

View All Articles

Related Posts