1

I want to mask my subdomain to a specific url on my main domain using .htaccess.

For example: https://sub.example.com to show the content of https://www.example.com/page/12345. And the URL is still https://sub.example.com

I have got the following in .htaccess:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^sub\.example\.com
RewriteRule ^https://sub\.example\.com https://www\.example\.com/page/12345

But if I go to https://sub.example.com, it shows content of https://www.example.com. Can't seem to figure out what's wrong. Please help!

eddeee888
  • 119
  • 1
  • 7

1 Answers1

1

Actually, you want to rewrite without redirecting. This requires enabling mod_proxy and mod_rewrite in Apache's httpd.conf.

Then, the rewrite should look like this:

Options +FollowSymLinks -MultiViews 
RewriteEngine On
RewriteCond %{HTTP_HOST}  ^sub\.example\.com$ [NC]
#only when there is query string and https on, if needed
RewriteCond %{QUERY_STRING} ^$
RewriteCond %{HTTPS} =on
RewriteRule ^$ https://www.example.com/page/12345? [R=301,NE,NC,L]

Reference:

wp78de
  • 18,207
  • 7
  • 43
  • 71