Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NGINX - Return 301 vs Rewrite

I use NGINX in my dedicated server.

I've a question about the return and rewrite 301.


Rewrite 301:

rewrite ^ http://xxx.xxxxx.net/xx-xxx/$request_uri? permanent;

Return 301:

location ~ redirect-this/?$ {
    return 301 http://xxx.xxxxx.net/xx-xxx/redirect-this$1;
}

All redirects work correctly. But..

Which is the most effective method to make a 301 redirect?

I've more than 200 url to redirect. So, what you recommend?

like image 487
Ferrmolina Avatar asked May 11 '15 10:05

Ferrmolina


People also ask

What is return 301 in NGINX?

301 Permanent Redirection Permanent redirection will inform the browser that the website is no longer available with the old URL and this information should be updated and this point to the new URL we published.

What does NGINX rewrite do?

NGINX rewrite rules are used to change entire or a part of the URL requested by a client. The main motive for changing an URL is to inform the clients that the resources they are looking for have changed its location apart from controlling the flow of executing pages in NGINX.

What is return in NGINX?

According to the NGINX documentation, use return if you can. It is simpler and faster because NGINX stops processing the request (and doesn't have to process a regex).

What is the difference between rewrite and redirect?

Simply put, a redirect is a client-side request to have the web browser go to another URL. This means that the URL that you see in the browser will update to the new URL. A rewrite is a server-side rewrite of the URL before it's fully processed by IIS.


Video Answer


1 Answers

As stated in the nginx pitfalls you should use server blocks and return statements as they're way faster than evaluating RegEx via location blocks.

Since you're forcing the rewrite rule to send a 301 there's no difference when it comes to SEO, btw..

like image 160
VF_ Avatar answered Oct 10 '22 18:10

VF_