I am trying to forward with masking a Bluehost subdomain (login.example.com) to another Bluehost subdomain (login.example.ca). I did the following;

RewriteEngine On
RewriteCond %{HTTP_HOST} ^login.example.com
RewriteRule ^(.*) https://login.example.ca/directory [P]

But it is not working, Is there a way to do this?

  • 1
    Masking is fairly complicated and requires the target server to be configured to accept requests from the origin server (if using two servers) or on the same server, for example using a virtual host file. Reverse proxies can accomplish this, but the discussion on how to set one up is outside the scope of this site. Check if your domain registrar provides forwarding with masking, which is usually done with an iframe. See the following related question: Bluehost - Forward Subdomain with masking.
    – dan
    Commented Aug 1, 2020 at 0:32
  • @dan "forwarding with masking" usually involves a frame set. It doesn't usually work very well because it isn't good for usability or SEO, but it doesn't require cooperation from the other server. The given code isn't a redirect because the [P] flag in mod_rewrite is "reverse proxy". Commented Aug 1, 2020 at 9:06
  • @QilqamishSumer Do you control both domains? If you want to show the login page from the other site, what is the purpose? Which site do you want the user to log in to? Which site should get login cookies set? Do you need both the login page and the submitted login form to go to the other site? Do you need the user to come back to the first site after login? Commented Aug 1, 2020 at 9:11
  • @StephenOstermiller This is for a login page, so SEO really isn't a factor here (nor was it tagged with SEO). Both domains would need to need to be setup on the server (using a virtual host) or with a ServerAlias - see DocRoot's answer in the linked question, or this one on Server Fault. Given that the OP is just asking about .htaccess and Bluehost (which is often shared hosting), I don't think the OP is aware of how complicated that might get, or if it's even possible given their type of account...
    – dan
    Commented Aug 1, 2020 at 9:54
  • ...the P flag also causes the request to be handled by mod_proxy, which I do not think is installed in most cPanel installs, particularly in shared hosting accounts (I couldn't find any reference to using mod_proxy with Bluehost, or "masking" either). Without that module installed, it will just ignore it and act as a redirect without masking.
    – dan
    Commented Aug 1, 2020 at 10:18


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.