Hi, I would like to rewrite several domains to from .example.com to
www.example.com. I think the best way is to use a wild card. Too bad I
suck at rewrite rules. Haha
Can someone help me make the following work?
if ($host != 'www.*.com') {
rewrite ^/(.*)$ http://www.*.com/$1 permanent;
}
Regards,
-Team AMP
http://www.ampprod.com
On Sat, Sep 05, 2009 at 08:57:57AM -0500, AMP Admin wrote:
Hi, I would like to rewrite several domains to from .example.com to
www.example.com. I think the best way is to use a wild card. Too bad I
suck at rewrite rules. Haha
Can someone help me make the following work?
if ($host != 'www.*.com') {
rewrite ^/(.*)$ http://www.*.com/$1 permanent;
}
server {
server_name ~^((?:domain1|domain2|domain3).com)$;
set $name $1;
rewrite ^ http://www.$name$request_uri? permanent;
}
Thanks. I’ll do that. I was just hoping that I wouldn’t have to list
all
domains. That works though.
Regards,
-Team AMP
http://www.ampprod.com
Hi,
Cliff W. wrote:
Try this:
server {
server_name ~(^.+…+$);
set $name $1;
rewrite ^ http://www.$name$request_uri? permanent;
}
That will cause problems if the domain begins with www. If you want to
capture both www.domain.tld and domain.tld and rewrite to include the
www., you could use
server {
server_name ~^(www.)?(.+)$;
set $name $2;
rewrite ^ http://www.$name$request_uri? permanent;
}
Marcus.
That goes rewrites to http://www…com/
Try this:
server {
server_name ~(^.+…+$);
set $name $1;
rewrite ^ http://www.$name$request_uri? permanent;
}
Regards,
Cliff
Try
server {
listen 80;
server_name ~^[^.]+.[^.]+$; # domain.com
rewrite ^ http://www.$host$request_uri?;
}
from Re: Mass virtual hosting and global redirect
testbot Wrote:
Cliff
http://www.ampprod.com
On Sat, Sep 05, 2009 at 08:57:57AM -0500, AMP
if ($host != 'www.*.com') {
}
–
vonage sucks - Google Search
Posted at Nginx Forum:
On Sunday, September 6, 2009 at 7:29:09, Igor S. wrote:
IS> server {
IS> server_name ~^([^.].com)$;
IS> set $name $1;
IS> rewrite ^ http://www.$name$request_uri? permanent;
IS> }
server {
server_name ~^(?!www\.);
rewrite ^ http://www.$host$request_uri? permanent;
}
(c) Igor S., 15 Sep 2008,
http://www.lexa.ru/nginx-ru/msg19431.html
On Sun, Sep 06, 2009 at 08:29:09AM +0400, Igor S. wrote:
...
}
server {
server_name www.*;
…
}
server {
server_name ~^([^.].com)$;
I tried all of the replies and the following worked best.
server {
listen 80;
server_name www.*;
… websites configuration below here
}
server {
server_name ~^(?!www.);
rewrite ^ http://www.$host$request_uri? permanent;
}
Thanks everyone!
On a site note… this is for sites that are on hold (future projects),
no
longer needed (for sale), and/or being worked on. The list of sites is
50+
right now. Their content is dynamically generated using the $host name.
That why this was so important to me. Now I can just point new or old
domains to this ip address and that’s it until we’re ready to work with
them.
On Sat, Sep 05, 2009 at 11:28:14AM -0500, AMP Admin wrote:
Thanks. I’ll do that. I was just hoping that I wouldn’t have to list all
domains. That works though.
You should use positive logic: configure all sites and redirect
remainder using regex:
server {
server_name www.domain1.com;
…
}
server {
server_name www.domain2.com;
…
}
server {
server_name www.domain3.com;
…
}
server {
server_name www.*;
…
}
server {
server_name ~^([^.].com)$;
set $name $1;
rewrite ^ http://www.$name$request_uri? permanent;
}
nginx tests server names for the first match in following order:
- exact names,
- *.name wildcards,
- name.* wildcards,
- regex names in order of their appearance.
On Sat, 2009-09-05 at 23:53 +0300, Marcus C. wrote:
That will cause problems if the domain begins with www. If you want to
capture both www.domain.tld and domain.tld and rewrite to include the
www., you could use
That’s odd, as I tested it and it worked fine It specifically does
not match domains starting with any subdomain, it leaves that to another
server section. Here’s the complete test I used:
server {
server_name ~^(.+\..+)$;
set $name $1;
rewrite ^ http://www.$name$request_uri? permanent;
}
server {
server_name www.test1.com;
root /var/www;
autoindex on;
}
I tested with both http://test1.com and http://www.test1.com and got the
expected results.
Regards,
Cliff
Hi,
Cliff W. wrote:
set $name $1;
That’s odd, as I tested it and it worked fine It specifically does
not match domains starting with any subdomain,
I think if you look at your regex again, you’ll see that it’s not that
it doesn’t match any domains with sub domains, it matches any domains
with a dot somewhere in the middle. The . guarantees that there’s a
dot, but the other characters can be anything.
server_name www.test1.com;
root /var/www;
autoindex on;
}
That will work because the second server will capture the www.test1.com,
and the first will capture test1.com. The second domain is matched
before the first because it’s an exact match.
However, if you just have the first pattern, then you’ll get the rewrite
as http://www.www.test.com$request_uri. If you want to define the
sub-domains separately, then of course that’s fine, but you have to
remember that there might be some domains with a single tld (e.g.
test.com) and others with a country code too (e.g. test.co.uk). If
you’re going to have a catch-all, then it’s easier to stick to one regex
IMHO.
Of course though, (as Igor mentioned) it’s more efficient to define all
the domains that you know the names of in the conf file itself.
Cheers,
Marcus.
On Sun, 2009-09-06 at 22:23 +0300, Marcus C. wrote:
www., you could use
That’s odd, as I tested it and it worked fine It specifically does
not match domains starting with any subdomain,
I think if you look at your regex again, you’ll see that it’s not that
it doesn’t match any domains with sub domains, it matches any domains
with a dot somewhere in the middle. The . guarantees that there’s a
dot, but the other characters can be anything.
Ah, so instead of .+ it’d need to be [^.]+ as in:
server_name ~(^[^.]+.[^.]+$);
Cliff
Hi,
I think if you look at your regex again, you’ll see that it’s not that
it doesn’t match any domains with sub domains, it matches any domains
with a dot somewhere in the middle. The . guarantees that there’s a
dot, but the other characters can be anything.
Ah, so instead of .+ it’d need to be [^.]+ as in:
server_name ~(^[^.]+.[^.]+$);
That would be fine - for domains with just the top level domain before
the main name, e.g. test.com. However, if you also deal with URLs with
a country code as well, e.g. test.co.uk, it’s not going to capture them
because they’ll look like the subdomains you were trying to avoid
capturing. You could create a rather complex RE using all the country
codes and tld’s to fully capture only the main domain, and no
sub-domains, but it’d be pretty long and would probably waste
considerable processing time. Personally, I like to keep things simple.
Cheers,
Marcus.
On Mon, 2009-09-07 at 13:44 +0300, Marcus C. wrote:
That would be fine - for domains with just the top level domain before
the main name, e.g. test.com. However, if you also deal with URLs with
a country code as well, e.g. test.co.uk, it’s not going to capture them
because they’ll look like the subdomains you were trying to avoid
capturing. You could create a rather complex RE using all the country
codes and tld’s to fully capture only the main domain, and no
sub-domains, but it’d be pretty long and would probably waste
considerable processing time. Personally, I like to keep things simple.
Well, my guess is that there’s no general regex that’s going to cover
the case of say:
files.domain.com → files.domain.com
test.co.uk → www.test.co.uk
I think the OP would have to make a choice based on his subset of
domains or setup special locations for places like files.domain.com
(which would probably be the right solution).
Cliff
How would this be in nginx:
<Files ~ “.xml$”>
Order allow,deny
Deny from all
Satisfy all
Regards,
-Team AMP
http://www.ampprod.com
====== CONFIDENTIALITY NOTICE ======
NOTICE: This e-mail message and all attachments transmitted with it may
contain legally privileged and confidential information intended solely
for the use of the addressee. If the reader of this message is not the
intended recipient, you are hereby notified that any reading,
dissemination, distribution, copying, or other use of this message or
its attachments is strictly prohibited. If you have received this
message in error, please notify the sender immediately and delete this
message from your system. Thank you.
How would this be in nginx:
<Files ~ “.xml$”>
Order allow,deny
Deny from all
Satisfy all
Regards,
-Team AMP
http://www.ampprod.com
====== CONFIDENTIALITY NOTICE ======
NOTICE: This e-mail message and all attachments transmitted with it may
contain legally privileged and confidential information intended solely
for the use of the addressee. If the reader of this message is not the
intended recipient, you are hereby notified that any reading,
dissemination, distribution, copying, or other use of this message or
its attachments is strictly prohibited. If you have received this
message in error, please notify the sender immediately and delete this
message from your system. Thank you.