Mask URL

How to Mask URL for a Subdomain in WordPress

If you run a WordPress site with a subdomain, you may want to mask the URL so visitors see only the main domain. Masking a subdomain means hiding the actual URL while keeping the content visible. If you want ‘yourmaindomain.com’ to show content from sub.yourmaindomain.com, or if you don’t, the browser will show sub.yourmaindomain.com.

URL masking is helpful for branding, user experience, and SEO. This guide will teach you different ways to mask a subdomain URL in WordPress.

Method 1: Use .htaccess for URL Masking

If your WordPress site is on Apache hosting, you can use .htaccess to mask the subdomain URL.

Steps to Mask Subdomain Using .htaccess

  1. Log in to Your Hosting
  • Open cPanel or FTP client (like FileZilla).
  1. Locate the .htaccess File.
  • Go to the public_html folder.
  • If you don’t see .htaccess, enable “Show Hidden Files” in cPanel.
  1. Edit .htaccess and Add This Code.

    RewriteEngine On

RewriteCond %{HTTP_HOST} ^sub.yourmaindomain.com [NC]

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

  1. Save and Upload the .htaccess file.

When users visit sub.yourmaindomain.com, they will only see yourmaindomain.com in the browser.

Method 2: Use an HTML Frame for Masking

If you can’t edit .htaccess, you can use an HTML frame to load the subdomain inside a page.

Steps to Use HTML Frame for URL Masking

  1. Create a New HTML File
  • Open Notepad (Windows) or TextEdit (Mac).
  1. Add This Code

    <html>

<head>

<title>My Website</title>

</head>

<frameset rows=”100%,*” frameborder=”no” border=”0″ framespacing=”0″>

    <frame src=”https://sub.yourmaindomain.com” noresize=”noresize” />

</frameset>

</html>

  1. Save the File as index.html

  2. Upload the File to your primary domain’s root folder.

Now, users will see yourmaindomain.com while browsing content from sub.yourmaindomain.com.

Method 3: Use Cloudflare for URL Forwarding

Cloudflare allows you to mask a subdomain URL by using page rules.

Steps to Mask a Subdomain Using Cloudflare

  1. Log in to Cloudflare
  2. Go to Page Rules

    • Click Page Rules in the left menu.
    • Click Create Page Rule.
  3. Set Up a Forwarding Rule
    • Enter sub.yourmaindomain.com/*.
    • Choose Forwarding URL > 301 Redirect.
    • Enter the target URL: https://yourmaindomain.com/$1.
  4. Save and Deploy.

Cloudflare will mask the subdomain, and visitors will only see yourmaindomain.com.

Method 4: Use a WordPress Plugin

If you don’t want to edit code, use a WordPress plugin to mask the subdomain.

Best Plugins for URL Masking

  1. WP Hide & Security Enhancer – Hides URLs and subdomains.
  2. Redirection – Redirects subdomains without showing them.
  3. Simple 301 Redirects – Easy URL masking.

Steps to Mask a Subdomain Using WP Hide Plugin

  1. Install and Activate WP Hide
    • Go to Plugins > Add New.
    • Search for WP Hide & Security Enhancer.
    • Click Install Now and Activate.
  2. Configure URL Masking
    • Go to Settings > WP Hide.
    • Look for URL Rewrite Settings.
    • Add sub.yourmaindomain.com and set it to show yourmaindomain.com.
  3. Save Changes.

Now, users won’t see the subdomain in the browser.

Method 5: Use CNAME in DNS Settings

A CNAME record in DNS can help point a subdomain to the main domain without changing the URL.

Steps to Set Up CNAME for URL Masking

  1. Log in to Your Domain Registrar
    • Open GoDaddy, Namecheap, Cloudflare, or your hosting provider.
  2. Go to DNS Settings
    • Find the DNS Manager.
  3. Add a CNAME Record
    • Name: sub
    • Type: CNAME
    • Value: yourmaindomain.com
  4. Save Changes.

This method points the subdomain to the main domain, keeping the URL masked.

FAQs

  1. Will URL masking affect SEO?

Yes. Search engines may not index masked URLs correctly. Use 301 redirects instead for SEO-friendly masking.

  1. Can I mask a subdomain with WordPress Multisite?

Yes! Go to Network Admin > Sites, edit the subdomain, and set the main domain as the primary URL.

  1. Is URL masking the same as a redirect?

No. Redirects send users to a different URL while masking hides the original URL.

  1. What if my hosting doesn’t allow .htaccess edits?

Use Cloudflare forwarding rules or an HTML frame method.

Conclusion

URL masking for subdomains helps maintain branding, improve user experience, and keep URLs clean.