1

On the server.rewrites file within the nginx/ map, I have the following logic for redirecting the homepage of an old domain, to the homepage of a new domain:

if ($http_host ~ ^(www\.)?olddomain.com ) {
   return 301 https://www.newdomain.com$request_uri;
}

This is not working as expected, because all other url's inside the old domain are also being redirected.

Example: olddomain.com/someurl is being redirected to newdomain.com/someurl, and the redirect should only work for the home page.

Any ideas on how I could adjust the above mentioned code? Thanks for your contributions.

1
  • location = / { }, location = /index.php { }, location = /index.html { }, – Anthony Jun 11 '19 at 8:30
0

in your server block for specific domain change root location to:

location = / {
    return 301 http://www.newdomain.com/;
}

http://nginx.org/en/docs/http/ngx_http_core_module.html#location

Let’s illustrate the above by an example:

location = / {
    [ configuration A ]
}

location / {
    [ configuration B ]
}

location /documents/ {
    [ configuration C ]
}

location ^~ /images/ {
    [ configuration D ]
}

location ~* \.(gif|jpg|jpeg)$ {
    [ configuration E ]
}

The “/” request will match configuration A, the “/index.html” request will match configuration B, the “/documents/document.html” request will match configuration C, the “/images/1.gif” request will match configuration D, and the “/documents/1.jpg” request will match configuration E.

The “@” prefix defines a named location. Such a location is not used for a regular request processing, but instead used for request redirection. They cannot be nested, and cannot contain nested locations.

1
  • Hi: thanks for your answer :) how would you tackle it if we have different stores views with different domains each one? – Julian Murillo Jun 17 '19 at 15:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.