开发者

How to Redirect any subdomain request to main domain?

开发者 https://www.devze.com 2023-02-20 00:23 出处:网络
I\'m trying to redirect all subdomain requests for domain.com to www.domain.com even when the subdomain do开发者_开发百科es not exist, for example if we have:

I'm trying to redirect all subdomain requests for domain.com to www.domain.com even when the subdomain do开发者_开发百科es not exist, for example if we have:

abc.domain.com to www.domain.com

Where abc can be any requests. Furthermore, that subdomain abc may be exists or not. But whatever it is, I want to redirect it to main domain.

And less important request is. How it is possible to keep the input address at the address bar and redirect to main domain?

It will be best for me if it is done by .htaccess

I use apache server.

Thank you.


Since you haven't specified the environment you use, here are some general tips:

First, there is a difference between redirecting: The user types sub.domain.com into the browser's address bar, but is redirected to domain.com -> domain.com is in the address bar, as the user is now on domain.com

...and rewriting an URL in the background: The user types in sub.domain.com and stays at this address. The user sees sub.domain.com but in the background some other page (in your case, that one under domain.com) is loaded and shown. (Quickly explained.)

If you are using Apache, take a look at 301 redirects and url rewriting.


In addition to what Piedone said (which is on the HTTP server side), you also need to configure the DNS to have a catch-all for all subdomains, directing them all to your HTTP server.

This implicitly means that all possible subdomains will exist automatically.

0

精彩评论

暂无评论...
验证码 换一张
取 消