Client provided a CSV file with several thousand redirects for site hosted on Plesk server. For maximum efficiency we implemented the redirects using a map file in Nginx.
Start by convert the CSV file to a map include file with one redirect per line, space delimited and terminated with a colon. For example:
1 2 |
/source-url-1 https://acme.com/dest-url-1: /source-url-2 https://acme.com/dest-url-2: |
I placed the file at:
/var/www/vhosts/acme.com/redirects/redirect.map
Next step is to add to global nginx config by creating a file at:
/etc/nginx/conf.d/redirect_maps.conf
containing:
1 2 3 4 5 6 |
map_hash_max_size 4096; map_hash_bucket_size 256; map $request_uri $new_uri { include /var/www/vhosts/acme.com/redirects/redirects.map; } |
Finally in Plesk, for the target subscription (acme.com) in “Apache & Nginx Setting” add the following to “Additional Nginx directives:
1 2 3 |
if ($new_uri != "") { rewrite ^(.*)$ $new_uri permanent; } |