1

I've recently received a request from the site owner to redirect our base domain to a specific landing page on a subdomain, which is working just fine. The problem is that he wants the URL to remain the same, so the user will see mydomain.com but go to sub.mydomain.com/index.php?landing

I did some research and found that the proper way to redirect a user while keeping the URL intact is to proxy the request, which, as far as I can tell, can be accomplished with the P flag in a RewriteRule. However, despite confirming that mod_proxy is indeed installed via WHM, the URL still gets rewritten to the landing page in the browser. Here's the relevant section of my .htaccess file for reference:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www.)?mydomain.com$
RewriteRule ^(.*)$ http://sub\.mydomain\.com/index\.php\?landing/ [P]

This is an AWS server using WHM/cPanel on CentOS 7.8 with a standard LAMP stack. I feel like this is probably something simple that I'm overlooking, so hopefully someone can provide some insight. I've used mod_rewrite many times in the past, but I've never had to proxy a request like this.

3
  • If this was previously implemented as a 301 (permanent) redirect then make sure you're not seeing a cached response. What is the "redirect" you are seeing exactly? If the subdomain is triggering the redirect then you'll need to configure ProxyPassReverse in the server config. Is the main domain and subdomain pointing to different filesystems/servers? (If they are on the same filesystem then you may not need to proxy the request?)
    – MrWhite
    Commented Sep 25, 2020 at 20:38
  • @MrWhite It was previously a 301, but it's not just a cached response. The .htaccess I provided above is at the doc root of the main domain, redirecting it to the subdomain. The subdomain doesn't redirect anything. The redirect is working; I just don't want the URL to change. These are indeed on the same server, although the subdomain is stored in a different user's home (which really shouldn't be an issue, truthfully). Commented Sep 25, 2020 at 21:34
  • The above won't trigger a "redirect" by itself, so if you are not seeing a cached response then there must be something else that is triggering this?
    – MrWhite
    Commented Sep 29, 2020 at 14:46

0

You must log in to answer this question.

Browse other questions tagged .