Search code examples
phpapache.htaccesssubdomainhosting

How to redirect non-existing subdomain to another subdomain?


I have the following issues with subdomains in my hosting:

  1. I have a subdomain, let's say shop.abc.com
  2. Now I check on my log file, there are people accessing through something.shop.abc.com while subdomain something does not exist.
  3. The subdomain "something" is not just "something" but rather random like xyz.shop.abc.com, rex.shop.abc.com, etc.
  4. Another strange thing is that the rest of the URL is correct, for example, rex4534.abc.com/cat1/article2, "cat1/article2" is the correct URL segment.

Is it possible to redirect these non-existing subdomains to the correct subdomain while keeping the URL segment? Can it be done through .htaccess?

I put this line on .htaccess, but it doesn't work and causes a redirect if I access shop.abc.com

RewriteRule ^ http://shop.abc.com%{REQUEST_URI} [R=301,QSA,L]

Thanks.


Solution

  • simply add " *.shop.abc.com" host and point it to where ever you want.