Now Reading
Redirect Niginx Magento front end to new website while maintaining admin access on old website
0

Redirect Niginx Magento front end to new website while maintaining admin access on old website

by Simon ParkerMay 24, 2020

I had a client who wanted their old Magento based site to redirect all front end users to their new domain while still maintining admin access so they could continue to use their Amazon integration for managing orders and stock.

This is actually fairly straightforward with Nginx but needs a couple of entries to ensure it works.

You will have an entire nginx conf file for this site but qwe will just be modifying the following line

location / {
    try_files $uri $uri/ /index.php?$args;

}

This line usually just sends all requests to be processed by php and we want to change that so that all instead redirected to the new domain

We do this by changing this to a redirect

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

In this case the client wanted to maintain access to the admin area of the site as he was using the Magento amazon integration through M2EPro and wanted to continue to do that.

So we add in a second location block which matches the admin path

location /admin {
    try_files $uri $uri/ /index.php?$args;
}

For obvious reasons you should always change your admin path on a live website but this is just for the example.

The admin login page however when you actually login will redirect you to the usual index.php file to display the admin area adding on a token for that session.

So we need to add a final location block to handle this request path also.

location /index.php/admin {
    try_files $uri $uri/ /index.php?$args;
}

This allows the post login page to work correctly. again replace /admin with whatever your admin path is.

We now have all front end requests redirecting to the new domain and the admin area intact.

Final note if you want to redirect the old site with a full url then add the following in place of the first lcoation edit

location / {
    return 301 https://www.newdomain.com$request_uri;
}
What's your reaction?
Love It
0%
Interested
0%
Meh...
0%
What?
0%
Hate It
0%
Sad
0%
About The Author
Simon Parker

Leave a Response