0
Є відповідь

301 redirect howto?

Frederik H-Henriksen 10 років тому оновлений 10 років тому 9
How to do a permanemt 301 redirect using nginx? I want eg. www.domain1.com & domain1.com to point to domain3.com

domain3.com already has a website created in ajenti using nginx.

I need this as I have a lot domains that need to point to domain3.com or subfolders/pages on that domain

Thank you.

Відповідь

Відповідь
Є відповідь
You can do this by adding another website for www.domain1.com, and adding this custom website configuration:

rewrite ^ http://domain3.com$request_uri permanent;

(from http://stackoverflow.com/questions/7947030/nginx-no-www-to-www-and-www-to-no-www)
ДОБРЕ, Я ЗАДОВОЛЕНИЙ
PERFECT A++++
Позначка задоволеності від Frederik H-Henriksen 10 років тому
Відповідь
Є відповідь
You can do this by adding another website for www.domain1.com, and adding this custom website configuration:

rewrite ^ http://domain3.com$request_uri permanent;

(from http://stackoverflow.com/questions/7947030/nginx-no-www-to-www-and-www-to-no-www)
Thank you but I dont see a 301 in there? The 301 redirect is important for SEO. Also does this redirect both www -> no www and no www -> no www?
'permanent' will instruct NGINX to send '301 Moved Permanently' response.
Thank you I will test that. And my dns updates.

I have another problem. Added these:

website1.com

website2.com 

on 2 websites in the manager and in the domains under the manager: website1.com for #1 and website2.com for #2. 

However if I enter www.website1.com it points me to website2.com ? What happened here ? 


Thank you
Have you created a website for www.website1.com / added a www.website1.com domain to some website? If www.website1.com domain is unknown to NGINX, it will point you to an random website of yours. Note: 'www.' is a subdomain like any other.
I have just added www.website1.com to the same config under domains. Strangely enough it still sends me to website2.com. 

How about typo errors ? What if someone makes subdomain typos? Can I use a wildcard like *.website1.com ? For anything that is "NOT" defined?
Yes, you can use any wildcards (examples: http://nginx.org/en/docs/http/server_names.html#wildcard_names). Also, you can mark one of the ports in websites as Default, and it will receive all requests with unknown domains on this port.
Thank you for your swift responses and very accurate answers. I hope *.website.com should be enough for me.