New

The new HostCloud is live. Web Hosting for ₹1 for your first month.

Web Hosting for ₹1 · first month

Claim offerClaim
WordPress

IP canonicalization for WordPress: redirect your server IP address to your domain

If your site loads at both yourdomain.com and its raw IP address, search engines can see duplicate copies. Here is how to check, how to redirect the IP to your domain with Apache, LiteSpeed or Nginx and what to expect on shared hosting.

3 November 2026 · 8 min read
IP canonicalization for WordPress: redirect your server IP address to your domain

IP canonicalization for WordPress: redirect your server IP address to your domain

TL;DR: IP canonicalization means making sure your website is reachable at only one address. If visiting your server's IP address, or the www and non-www versions, shows the same site without redirecting, search engines may see several copies of every page. The fix is a permanent 301 redirect from the IP address, and from the version you do not want, to one preferred HTTPS domain. On a VPS you can do this in .htaccess or in your Nginx config. On shared hosting, the IP often serves a default page rather than your site, so check first. Then test with curl and confirm your canonical tags agree.

What IP canonicalization is

"Canonical" means the one official version. Your site can often be reached in several ways:

  • https://example.com
  • https://www.example.com
  • http://example.com and http://www.example.com
  • http://203.0.113.10, the server's IP address

If all of these return the same content with a normal 200 response, they are different URLs for the same page. IP canonicalization is the practice of redirecting all the unwanted versions to the single one you want people and search engines to use.

Why it matters

  • Duplicate content. Search engines may find your site through the IP address, for example through an old link or a scan, and treat it as a duplicate. They normally pick a canonical version themselves, but they might not choose the one you want.
  • Split link signals. If other sites link to the IP or the wrong host name, those links do not all help your preferred address.
  • Cleaner analytics and logs. Fewer address variants mean simpler reports.
  • Less exposure. Bots scan IP ranges for known software. A site that answers on the bare IP gives them one more way in. Redirecting or refusing those requests does not replace security, but it reduces noise. See securing the WordPress admin against brute-force logins.

For many small sites the practical effect on rankings is small, but it is a quick fix, and it is part of getting a clean technical foundation. Our guide to canonical tags and duplicate content explains the related on-page signal.

Diagram showing four URL variants, the server IP, www, non-www and HTTP, all redirected with a 301 to a single preferred HTTPS address

Step 1: check whether you have the problem

Replace the example values with your own domain and IP address. First, find your server's IP:

dig example.com A +short

Then request the site by IP:

curl -I http://203.0.113.10

Read the first line of the result.

  • 301 or 302 with a Location: header pointing to your domain: already redirecting. Good.
  • 200 OK: the IP serves content. Now check whether it is your site or a default page.
  • 403, 404 or a connection refused: the IP does not show your site, so there is nothing to canonicalize.

To see your site's content when you use the IP, open http://203.0.113.10 in a browser. If it shows your homepage, you have duplicate access.

Also test the host name variants:

curl -I http://example.com
curl -I http://www.example.com
curl -I https://www.example.com

Only one of these should return 200. The others should redirect to it. Our guide to looking up DNS records shows how to confirm what each name points to.

Step 2: choose one preferred address

Decide on your canonical version, then use it everywhere:

  • HTTPS rather than HTTP
  • www or non-www, one of them
  • your domain rather than the IP

For example, you might choose https://example.com. Set the WordPress Address and Site Address to match, and make your sitemap and canonical tags use the same version. If you have not yet forced HTTPS, do that first. See how to force HTTPS on WordPress and moving from HTTP to HTTPS without losing rankings.

Step 3: redirect on Apache or LiteSpeed

Add this rule to the .htaccess file in your site root, above the # BEGIN WordPress block. It redirects requests made to the IP address to your domain:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^203\.0\.113\.10$
RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]
</IfModule>

The dots in the IP are escaped with backslashes because they are special characters in this pattern. Replace the IP and the domain with your own.

To also send the www version to the non-www version, add:

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

Place any such rules before the WordPress block, and combine them with your HTTPS redirect so a visitor goes through as few hops as possible. Always keep a copy of the old file, because a typing error can cause a 500 error. If that happens, see fixing the 500 internal server error.

Step 3 alternative: Nginx

Nginx does not use .htaccess. Create a server block that catches requests that do not match your domain, and redirect them:

server {
    listen 80 default_server;
    listen [::]:80 default_server;
    server_name _;
    return 301 https://example.com$request_uri;
}

An alternative for stricter behaviour is to refuse requests that do not name your domain, by returning 444, which closes the connection without a reply:

server {
    listen 80 default_server;
    server_name _;
    return 444;
}

Then make sure your real server block lists your actual domain names in server_name. Test and reload:

sudo nginx -t
sudo systemctl reload nginx

If you host several sites on one server, the default server block matters, because Nginx uses it for any request whose host name does not match a site.

What about shared hosting?

On shared hosting, many accounts live behind one IP address. When someone requests the bare IP, the server cannot tell which account they want, so it usually shows a default page, a host landing page or an error. That means your site normally is not reachable at the IP, and nothing needs fixing.

Do check, though. A few shared hosts route the IP to the first account on the server, which could be yours. If curl -I shows your content at the IP, you can add the .htaccess rule above, since you control your own .htaccess. If the IP shows another site's content or a default page, leave it alone. For the www and HTTPS variants, .htaccess rules work on shared hosting as normal.

Certificates and HTTPS on the IP

Browsers will show a certificate warning if someone opens https://203.0.113.10, because your certificate is issued for your domain, not the IP. That is expected and not a problem for visitors who use your domain. You can still redirect plain HTTP on the IP to your domain, and for the HTTPS-on-IP case, a default server block that refuses the connection is a clean approach. Do not try to buy a certificate for a shared IP address.

For keeping your real certificate valid, see automatic SSL renewal.

Test the result

After the change, run these again:

curl -I http://203.0.113.10
curl -I http://example.com
curl -I http://www.example.com
curl -I https://www.example.com
curl -I https://example.com

Expected pattern:

Address Expected result
http://203.0.113.10 301 to https://example.com/
http://example.com 301 to https://example.com/
http://www.example.com 301 to https://example.com/
https://www.example.com 301 to https://example.com/
https://example.com 200

Also test a deep URL, for example /blog/some-post/, to check the path is carried across. Use a private browser window, because browsers cache redirects.

Common mistakes

  • Redirect chains. HTTP to HTTPS, then www to non-www as a second hop. Combine them into one redirect where possible.
  • Redirect loops. Conflicting rules between .htaccess, a plugin and a CDN. Keep one source of truth. See fixing too many redirects.
  • Using a 302. Temporary redirects do not carry ranking signals as clearly as permanent ones. Use 301 for permanent moves. See 301 vs 302 redirects.
  • Forgetting canonical tags and sitemaps. They must show the same preferred URL.
  • Editing the wrong file. Nginx ignores .htaccess.
  • Redirecting everything on a multi-site server. A catch-all rule can send other sites' traffic to the wrong domain. Be specific about the host name you match.

FAQs

What is IP canonicalization?

Making sure your site is accessible at only one address by redirecting the server IP and other variants to your preferred domain.

Is it bad for SEO if my site loads on its IP address?

It can create duplicate versions of your pages. Search engines usually choose a canonical version, but redirecting the IP removes the ambiguity.

How do I redirect an IP address to a domain in WordPress?

On Apache or LiteSpeed, add a rewrite rule in .htaccess that matches the IP as the host and sends a 301 to your domain. On Nginx, use a default server block with a redirect.

Does shared hosting need this?

Usually not, because the bare IP normally shows a default page. Test it first with curl -I.

Should I use 301 or 302?

Use a 301 permanent redirect, since you want the preferred address to replace the others for good.

Will this fix www vs non-www too?

Not by itself. You need a separate rule for the host name variant, though you can put both in the same file.

Does it affect my SSL certificate?

No. Your certificate stays valid for your domain. Visiting the IP over HTTPS shows a name mismatch warning, which is normal.

How do I check if it worked?

Run curl -I against the IP and each host name variant. All but your preferred address should return a 301 to it.

Conclusion

IP canonicalization is a small, tidy fix: pick one preferred HTTPS address, redirect the server IP and the other variants to it with a permanent 301, and confirm your sitemap and canonical tags agree. Check first whether you actually have the problem, especially on shared hosting, then test every variant with curl.

HostCloud's hosting plans give you control over redirects and clean URLs for your WordPress site. See the options at https://hostcloud.in.

Sources:

Related posts