S
S
sumyuga2014-05-15 15:20:37
Nginx
sumyuga, 2014-05-15 15:20:37

Redirect or alias - how to redirect from one domain to another?

Greetings. There are two identical domains in different .ru and .com zones - you need to redirect from .com to .ru
The site in the .ru zone is working, and .com as an alias to it
How will it be kosher to make a redirect?
Previously, under Apache in .htaccess there was an entry Redirect 301 / site.ru
Now the nginx web server.

Answer the question

In order to leave comments, you need to log in

5 answer(s)
V
Vlad Zhivotnev, 2014-05-15
@sumyuga

A redirect is when you are redirected to another URL when you try to access the desired domain. In nginx it's better to do it like this:

server {
listen 80; #или гдетамувас
server_name site.com;
return 301 $scheme://$http_host$request_uri; 
}

Alias ​​- when two domains show the same content (without redirects).
Then simply:
server_name site.com site.ru;And the rest of the configuration as usual.

I
Igor, 2014-05-15
@merryjane

In the config for site.com:

location / {
            rewrite ^/(.+)$ http://site.ru/$1 permanent;
      }

thus, a 301 redirect will be implemented at the nginx level to the domain in the ru zone.

S
sumyuga, 2014-05-15
@sumyuga

those. is it better to solve such a problem on the side of the web server, and not with an NS CNAME record?
and what is the difference between your variant and these two:

server {
server_name site.com;
rewrite ^/(.*)$ site.ru/$1 permanent;
}

server {
server_name site.com;
return 301 $scheme://site.ru$request_uri;
}

A
Andrey Motorov, 2015-10-25
@turbopower

so no one answered ...
what method and how will it affect the search position of the site?

I
Igor Che, 2016-02-13
@chewarer

I was also looking for how to do it. I have Apache + Nginx.
I decided this:
In Apache for the domain I added this:

ServerName domain.ru
ServerAlias www.domain.ru otherdomain.ru www.otherdomain.ru

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question