Default nginx rewrite with regexp

Hello,

I’m working on a default server_name that match everything but
www.domain.tld
then rewrite to www.domain.tld. I use nginx 1.2.1-2.2+wheezy3 with a big
regexp.

I have an issu with tld that contain a dot (co.uk co.au net.au, etc…).

I must be able to make a difference between domain.co.uk and
foo.domain.com
first must rewrite www.domain.co.uk second, to www.domain.com

Previously, I had this regexp that does not working with any tld that
contain a
dot :

server_name
~^((?(w(w[^w]?.)?)|([^w]?.)).)?(?<domain_name>[^.]+).(?[^.]+)$;
rewrite ^ http://www.$domain_name.$tld$request_uri? permanent ;

Now I tryto do something like that :

server_name
“~^((?(w(w[^w]?.)?)|([^w]?.)).)?(?<domain_name>[^.]+)(?((.[^.]{1-3}\b){1,2}))$”;
rewrite ^ http://www.$domain_name$tld$request_uri? permanent ;

But I don’t find any clean solution. Is there a solution for that ? or I
must
still list all domains in my vhost ?

Best regards


Yoann Moulin

On Mon, Nov 17, 2014 at 02:22:48PM +0100, Yoann Moulin wrote:

Hi there,

I’m working on a default server_name that match everything but www.domain.tld
then rewrite to www.domain.tld.

It sounds like you may have better luck letting other server{} blocks
use
expected server_name:s; and just let the default match everything else.

But I’m not exactly sure what it is that you do want to do and don’t
want to do.

I must be able to make a difference between domain.co.uk and foo.domain.com
first must rewrite www.domain.co.uk second, to www.domain.com

Have you a list or a pattern of which endings should match the first
pattern, and which the second? Because if you do not, you cannot
expect nginx to know that one.two.abc should be handled differently
from one.two.xyz.

But I don’t find any clean solution. Is there a solution for that ? or I must
still list all domains in my vhost ?

If you can specify the problem exactly, it may be possible to arrive at
a solution.

If you can’t, it probably won’t be.

What should happen to a request for a.b.domain.co.uk? Or
www.b.domain.co.uk?

Good luck with it,

f

Francis D. [email protected]

Hi,

I’m working on a default server_name that match everything but www.domain.tld
then rewrite to www.domain.tld.

It sounds like you may have better luck letting other server{} blocks use
expected server_name:s; and just let the default match everything else.

But I’m not exactly sure what it is that you do want to do and don’t
want to do.

The final goal is for a single wordpress multisite vhost that able to
deliver
many domain without touching the vhost when customers want to add a new
domain.

I must be able to make a difference between domain.co.uk and foo.domain.com
first must rewrite www.domain.co.uk second, to www.domain.com

Have you a list or a pattern of which endings should match the first
pattern, and which the second? Because if you do not, you cannot
expect nginx to know that one.two.abc should be handled differently
from one.two.xyz.

The main vhost is www.* and the default one is for everything else and
the idea
is to rewrite to www.*.

domain.com|ww.domain.com => www.domain.com
domain.co.uk|ww.domain.co.uk => www.domain.co.uk

I just look for a generic vhost that able to match all domains with all
tld and
gtld, but It seem that I don’t have any solution.

But I don’t find any clean solution. Is there a solution for that ? or I must
still list all domains in my vhost ?

If you can specify the problem exactly, it may be possible to arrive at a
solution.

If you can’t, it probably won’t be.

make sense :slight_smile:

What should happen to a request for a.b.domain.co.uk? Or
www.b.domain.co.uk?

I haven’t this case (and hope won’t have… never and my customer knows
that)

Thanks for you help


Yoann