I want to redirect url's like: http://subdomain.domain.com/r/wtf to http://domain.com/r/wtf
How do I do this?
I want to redirect url's like: http://subdomain.domain.com/r/wtf to http://domain.com/r/wtf
How do I do this?
If is evil!. And if on every request is double facepalm ...
server {
listen 80;
# listen 443;
server_name *.domain.tld;
return 301 $scheme://domain.tld$request_uri;
}
server {
listen 80;
# listen 443;
server_name domain.tld;
# usual lines
}
With a rewrite rule, I have something like this in my nginx config doing exactly that:
if ($host !~ ^(www\.kaarsemaker\.net|ip\.seveas\.net)$) {
rewrite ^(.*)$ http://www.kaarsemaker.net$1 permanent;
}
The simplest answer:
if ($host !~ ^domain\.tld$){
rewrite ^/(.*) http://domain.tdl/$1 redirect;
}
Because you've asked all subdomains to one domain, so that rule would apply to any subdomain.
Edit: That meant to be inside a server definition, the one that is not the same as ^domain.tld$.