How To

How to Mask URL for Subdomain in WordPress

Masking a subdomain URL: reverse proxy, iframe or redirect, the SEO and security cost of each, and working Nginx, Apache and Cloudflare setups.

Shashank Dubey
·12 min read
Browser address bar showing example.com/blog/ instead of blog.example.com, with three options compared: reverse proxy, iframe and redirect

Masking a subdomain URL means visitors see one address, such as example.com/shop/, while the page is really served by another host, such as shop.example.com. There are only three ways to do it: a reverse proxy that fetches the subdomain behind the scenes, an iframe that frames it, or a redirect that does not mask anything at all. Only the reverse proxy is a real, search-friendly mask; the iframe breaks logins and SEO, and the redirect simply sends people to the subdomain.

Our team rewrote this guide on 18 November 2026 because the old version mixed those three up, as many tutorials do. Below we show what each method really does, the SEO and security cost of each, working configurations for Nginx, Apache and Cloudflare Workers, and when you should skip masking and use domain mapping or a plain redirect instead.

What does masking a URL for a subdomain actually mean?

The phrase gets used for three different setups, and they behave nothing alike. Before you change a single setting, decide which one you mean.

Method

Address bar shows

Who serves the HTML

Is it really masking?

Reverse proxy

The main domain path, e.g. example.com/shop/

The subdomain server, fetched by your proxy

Yes

Iframe (frame forwarding)

The main domain, on every page

A near-empty wrapper page holding a frame

Visually only

Redirect (301 or 302)

The final destination URL

Whatever the destination is

No

A reverse proxy is a server that accepts the visitor’s request on your main domain, quietly requests the same path from the subdomain’s server, and passes the answer back. The browser never learns the subdomain exists. This is how companies run a separately hosted blog at /blog/ on their main site.

An iframe is what domain registrars call “forwarding with masking”. The registrar serves a tiny HTML page with one full-screen frame pointing at the real site. The address bar never changes, even when the visitor clicks deep into the site, which is exactly why it causes trouble.

A redirect tells the browser to go somewhere else. The address bar changes to the new URL. Plugins like Redirection, Cloudflare redirect rules, wp_redirect() and registrar “forwarding without masking” all do this. It is often the right answer, but it is not masking.

Is URL masking bad for SEO?

It depends entirely on the method. A correctly configured reverse proxy is neutral for SEO: search engines see normal pages at normal URLs, with no sign of the subdomain. Frame-based masking is poor for SEO, and a redirect is fine for SEO but moves the ranking signals to the destination rather than keeping them on the masked address.

Reverse proxy: fine, if you avoid duplicates

The risk with a proxy is duplicate content. The same article is now reachable at example.com/blog/post/ and at the origin address. Google’s spam policies define cloaking as presenting different content to users and search engines, and sneaky redirects as sending people somewhere unexpected; a proxy that shows everyone the same page is neither. What you do need is one canonical address. When WordPress on the origin has its Site Address set to the proxied path, its built-in canonical tag already points there, because core builds the canonical link from the permalink and the permalink from the home URL. Then block or redirect direct visits to the origin so search engines only find one copy.

Iframe masking: the content is not on your URL

With frame forwarding, the HTML at your masked address is a wrapper with almost no text. The real headings and paragraphs live at the framed URL. Google documents an indexifembedded robots rule precisely because it treats framed content as belonging to the framed page and only folds it into the embedding page in some cases. Every page of a framed site also shares one address, so you cannot link to, share or rank an individual inner page under your domain.

Redirects: honest, but not a mask

A 301 redirect passes visitors and search engines to the destination, and the destination is what ranks. That is right when you are moving content for good. It is wrong if your goal was to make the subdomain’s pages appear and rank under the main domain.

Read Google’s spam policies on cloaking and sneaky redirects before you build anything clever. Every method in this guide shows users and crawlers the same content, which keeps you on the right side of them.

Is URL masking safe?

Each method has its own security cost, and they are worth weighing before SEO.

  • Reverse proxy: your proxy now makes requests on visitors’ behalf. If any part of the target hostname comes from the request, an attacker can make your server fetch internal addresses. Apache’s own documentation for the rewrite proxy flag calls this a Server-Side Request Forgery (SSRF) risk and says to keep the scheme and hostname fixed. Never turn on a forward proxy (ProxyRequests On in Apache) to build a reverse proxy; Apache warns that open proxy servers are dangerous and notes that a reverse proxy does not need it.
  • Trusting forwarded headers: WordPress behind a proxy has to believe the X-Forwarded-Proto header to know the visitor used HTTPS. If the origin can also be reached directly, anyone can send that header. Restrict the origin to your proxy’s traffic.
  • Iframes: a page that lets itself be framed by any site can be used for clickjacking, where a hidden frame tricks users into clicking. That is why WordPress core sends X-Frame-Options: SAMEORIGIN and a frame-ancestors 'self' policy on the login screen and in wp-admin. Removing those headers so a masked frame can log in weakens your site.
  • Redirects: safe, as long as the destination is fixed. Redirect code that takes the target from a query string becomes an open redirect, which phishers love. In WordPress, prefer wp_safe_redirect() for anything built from user input.

If you want to see which headers your site currently sends, our guide to WordPress security headers, including X-Frame-Options shows how to check and set them.

How do I show a subdomain under my main domain without a redirect?

Use a reverse proxy on whatever already serves your main domain. The pattern is the same everywhere: requests for /blog/ on the main domain go to the origin server that runs the second WordPress, and that WordPress is told its public address is https://example.com/blog.

In the examples below, example.com is the public site and origin.example.net is the server running the WordPress you want to show at /blog/. That WordPress answers at the /blog/ path, either because it is installed in a blog folder or because its rewrite base is set that way.

Step 1: tell the origin WordPress its public address

Add these lines to wp-config.php on the origin, above the “That’s all, stop editing” line. The HTTPS check comes from the reverse proxy example in WordPress’s own HTTPS administration docs; we added an isset() guard so PHP 8 does not log a warning when the header is missing.

<?php
// Checked on 18 Nov 2026 against WordPress 7.1.4 and PHP 8.3.
// The public address visitors see. WordPress builds every link and the canonical tag from it.
define( 'WP_HOME', 'https://example.com/blog' );
define( 'WP_SITEURL', 'https://example.com/blog' );

// The proxy terminates HTTPS and talks to this server, so trust its forwarded scheme.
// Only safe when the origin accepts traffic from the proxy alone.
if ( isset( $_SERVER['HTTP_X_FORWARDED_PROTO'] )
	&& str_contains( $_SERVER['HTTP_X_FORWARDED_PROTO'], 'https' ) ) {
	$_SERVER['HTTPS'] = 'on';
}

If the blog already has content under the old subdomain address, update stored URLs in the database too. A plain SQL find and replace breaks serialized data, so use WP-CLI as shown in our WP-CLI search-replace guide, and always run it with --dry-run first.

Step 2: the Nginx version

On the server that answers for example.com, add a location block. When proxy_pass has no path after the host, Nginx passes the request URI unchanged, so /blog/hello/ reaches the origin as /blog/hello/.

# Checked on 18 Nov 2026. Inside the server block for example.com.
location /blog/ {
    proxy_pass https://origin.example.net;      # fixed host: never built from the request
    proxy_ssl_server_name on;                   # send SNI so the origin serves the right certificate
    proxy_set_header X-Forwarded-Host  $host;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Forwarded-For   $proxy_add_x_forwarded_for;
    proxy_set_header X-Real-IP         $remote_addr;
}

Step 3 (alternative): the Apache version

Apache needs mod_proxy and mod_proxy_http, and SSLProxyEngine for an HTTPS origin. ProxyPass belongs in the virtual host configuration, not in .htaccess. ProxyPassReverse rewrites the Location header on redirects from the origin, so a redirect never leaks the origin hostname to the browser.

# Checked on 18 Nov 2026. Inside <VirtualHost *:443> for example.com.
SSLProxyEngine on
ProxyRequests Off
ProxyPass        "/blog/" "https://origin.example.net/blog/"
ProxyPassReverse "/blog/" "https://origin.example.net/blog/"
RequestHeader set X-Forwarded-Proto "https"

Apache’s mod_proxy documentation covers every directive used here, including the open proxy warning.

Step 4: keep the origin out of search results

Now stop people and crawlers from reaching origin.example.net directly. The cleanest options are a firewall rule that only accepts your proxy’s IP addresses, or a secret header your proxy adds and the origin checks. Because the origin’s canonical tags already point at example.com/blog/, any copies that were crawled before you locked it down will consolidate over time.

Can I mask a URL with .htaccess?

Only if your host has the Apache proxy modules switched on, and many shared hosts do not. The old version of this article showed a rewrite rule with the [P] flag, which is the .htaccess way to proxy. Here is a corrected version that serves the origin’s /blog/ under the main domain:

# Checked on 18 Nov 2026. In example.com's .htaccess, ABOVE the "# BEGIN WordPress" block.
# Needs mod_rewrite, mod_proxy and mod_proxy_http on the server.
RewriteEngine On
RewriteRule ^blog/(.*)$ https://origin.example.net/blog/$1 [P]

Three things to know before you rely on it. First, the [P] flag implies [L], so no later rule runs for that request. Second, Apache’s rewrite flags reference warns that [P] uses the default proxy worker, which does not reuse connections, so it is slower than a ProxyPass setup. Third, the hostname in the target is fixed: only the path comes from the request, which is what the same page recommends to avoid SSRF. If the rule produces a 500 error, the proxy modules are missing and you need your host’s help or another method.

A rule that rewrites to a full URL without [P] is an external redirect, not a mask. Keep that in mind when you read older tutorials. For other .htaccess work, our .htaccess optimization guide explains where WordPress expects custom rules to sit.

Can Cloudflare mask a subdomain URL?

Yes, with a Worker, but not with the dashboard redirect settings. This trips up a lot of people. Cloudflare Page Rules are now marked deprecated, and Cloudflare’s migration guide maps the old “Forwarding URL” setting to Single Redirects, which send a 301 or 302. The address bar changes, so nothing is masked.

Origin Rules can rewrite the Host header or send a hostname to a different DNS record, which is how you would proxy without code, but Cloudflare’s plan table lists the Host header, SNI and DNS record overrides as Enterprise-only. On Free, Pro and Business plans, a Worker is the practical route. The Workers Free plan allows 100,000 requests per day, and the Paid plan starts at 5 US dollars a month with 10 million requests included, according to Cloudflare’s pricing page on the day we checked.

// Checked on 18 Nov 2026. Attach this Worker to the route example.com/blog/*
// The target host is fixed in code, never taken from the request.
export default {
  async fetch(request) {
    const url = new URL(request.url);
    url.hostname = 'origin.example.net';

    const proxied = new Request(url, request);
    proxied.headers.set('X-Forwarded-Host', 'example.com');
    proxied.headers.set('X-Forwarded-Proto', 'https');

    return fetch(proxied);
  },
};

The origin still needs the wp-config.php lines from Step 1. The Worker sets X-Forwarded-Proto itself, so the HTTPS check works whether or not the origin sits behind Cloudflare too. If you already use Cloudflare for caching, our WordPress CDN setup guide covers which cache settings to keep away from wp-admin and logged-in pages, and those same rules apply to the proxied path.

Why does my login break when the domain is masked?

Because the masked domain loads your site inside a frame, and WordPress refuses to show its login and admin screens in a frame from another site. Core hooks send_frame_options_header() to both login_init and admin_init, and that function sends X-Frame-Options: SAMEORIGIN plus Content-Security-Policy: frame-ancestors 'self'. The browser sees the frame belongs to a different origin and blocks it. Even where the form appears, third-party cookie rules in current browsers often stop the login cookie from being saved inside the frame.

You can remove those headers with remove_action(), and forum threads suggest exactly that, but you would be switching off clickjacking protection on your login page to keep a setup that also hurts SEO. We do not recommend it. Replace frame forwarding with a reverse proxy, domain mapping or an honest redirect.

Should I just use a redirect instead?

Often, yes. Ask what you are trying to achieve:

What you want

Best method

Why

A short, memorable link to a campaign page

301 or 302 redirect

Nobody minds the address bar changing; no proxy to maintain

A separately hosted blog or shop to live at a path on the main domain

Reverse proxy

The only method that keeps one domain for users and search engines

A multisite subsite on its own custom domain

Native domain mapping

Built into WordPress since 4.5, no masking needed

Content moving permanently from a subdomain to a folder

Move it, then 301 the old URLs

Ranking signals follow the redirect to the new home

Hide an affiliate or tracking link

Redirect plugin link

Masking a third-party site in a frame usually breaks their terms and their site

For a plain redirect in WordPress itself, use the Redirection plugin or a short snippet. Note that wp_redirect() sends a 302 unless you pass a status, so set 301 explicitly for permanent moves:

<?php
// Checked on 18 Nov 2026 (WordPress 7.1.4). In a small plugin or mu-plugin, not functions.php of a theme you update.
// Sends visitors on the old subdomain to the matching path on the main site, permanently.
add_action( 'template_redirect', function () {
	$host = isset( $_SERVER['HTTP_HOST'] ) ? strtolower( $_SERVER['HTTP_HOST'] ) : '';
	if ( 'old.example.com' !== $host ) {
		return;
	}
	$path = isset( $_SERVER['REQUEST_URI'] ) ? wp_unslash( $_SERVER['REQUEST_URI'] ) : '/';
	wp_safe_redirect( 'https://example.com/blog' . $path, 301 );
	exit;
} );

For wp_safe_redirect() to allow example.com as a destination, it must be the site’s own host or added with the allowed_redirect_hosts filter; otherwise WordPress falls back to the admin URL. The destination host here is fixed in code, so only the path comes from the request.

How do I point a custom domain at a multisite subsite?

If your “subdomain” is really a WordPress multisite subsite, you probably do not need masking at all. WordPress has supported domain mapping natively since version 4.5. Point the custom domain’s DNS at the network’s server, make sure the web server and SSL certificate answer for it, then in Network Admin open Sites, edit the subsite and change its Site Address (URL) to the full custom domain. The official multisite domain mapping guide also notes that if logins fail with a cookie error, you can define COOKIE_DOMAIN in wp-config.php.

The result is a real site on a real domain: no frames, no proxy, and each subsite keeps its own address in search results.

How to test that your mask works

Whichever method you pick, check it from outside before you call it done. These checks take ten minutes and catch nearly every problem we see.

  1. Open a private window and load https://example.com/blog/. Click three inner links. The address bar must stay on example.com/blog/... the whole time.
  2. View the page source and search for origin.example.net. Any hit means a URL was stored or generated with the old address; fix it with a dry-run search-replace.
  3. Check the canonical tag: <link rel="canonical"> must point at the example.com/blog/ address.
  4. Log in at https://example.com/blog/wp-login.php, save a draft and upload an image. Redirect loops here almost always mean the HTTPS check in Step 1 is missing.
  5. Request https://origin.example.net/blog/ directly from a different network. It should be blocked or redirect, not serve the site.
  6. Run curl -I https://example.com/blog/ and confirm a 200 status with no Location header.
# Checked on 18 Nov 2026. Expect HTTP 200 and no Location header.
curl -sI https://example.com/blog/ | grep -iE '^(HTTP|location|x-frame-options|content-security-policy)'

Common mistakes people report

These come up again and again in support forums. We paraphrase each one and link the original thread. Checked on 18 November 2026.

  • Inner pages jumping to the internal address, then a redirect loop. A self-hosted site behind HAProxy loaded its home page but every other link went to the internal IP. Setting the site URLs fixed the links but caused “too many redirects”, because SSL ended at the proxy and WordPress thought requests were plain HTTP. The poster fixed it by setting $_SERVER['HTTPS'] in wp-config.php. (WordPress.org forum, December 2025)
  • Login form failing inside a frame. A user needed their site to work inside an iframe and found that wp_login_form() did nothing there, while it worked when opened directly. Replies pointed to removing core’s frame-options header, which is the clickjacking protection described above. (WordPress.org forum, October 2020)
  • wp-admin stuck in a redirect loop on a subdirectory install behind Nginx. Switching a subfolder site to HTTPS broke the front end and admin with “too many redirects”. Removing the canonical redirect filter helped the front end only; the fix that worked was the forwarded-proto snippet in wp-config.php. (Local community forum, 2017)
  • Missing images and redirect loops behind an Apache reverse proxy. A company moved its homepage to WordPress behind an Apache proxy and spent weeks fighting redirect loops and broken images, the classic result of the origin not knowing its public address. (WordPress.org forum, 2015)
  • Expecting a forwarding domain to keep its own address. A site owner wanted visitors arriving on a second domain to stay on it while WordPress was hosted on the first, and found WordPress sent them to its configured address. WordPress only answers on the addresses it is configured for, which is why mapping or a proxy is needed. (WordPress.org forum, 2010)

Frequently asked questions

Is URL masking the same as cloaking?

No. Google defines cloaking as showing search engines different content from what users see. A reverse proxy or an iframe shows everyone the same content. Masking becomes a problem only when it is used to hide where users really end up.

Will masking a subdomain move its rankings to my main domain?

A reverse proxy combined with correct canonical tags and 301s from the old subdomain URLs moves the content to the main domain’s URLs over time. Frame masking does not, because the content stays at the framed address.

Can a WordPress plugin mask a URL?

Redirect plugins redirect; they do not mask. Plugins that claim to “mask” usually use a frame. A true mask has to happen at the server, CDN or proxy layer, before WordPress runs.

Does the origin need its own SSL certificate?

Yes, if your proxy connects to it over HTTPS, which it should when the traffic crosses the internet. The certificate must match the hostname the proxy connects to, which is why the Nginx example turns on SNI.

What about WooCommerce checkout behind a proxy?

It works when the origin knows its public HTTPS address and forwarded headers are set, but test the whole flow, including payment gateway return URLs and webhooks, which must use the public domain.

Is domain forwarding with masking from my registrar ever fine?

For a one-page holding site with no login, forms or need for search traffic, it does little harm. For a real WordPress site, use DNS to point the domain at your host instead.

Part of the Wbcom Designs family

The all-in-one WordPress community stack

Also ours: wbcomdesigns.comvapvarun.combrndle.com