By tAALz
I have 200 URLs that I need to redirect to new URLs e.g. http://abc.com/one/p-SF10 -----> http://abc.com/one/p-SF134 http://abc.com/one/p-SM28 -----> http://abc.com/one/p-SM28 http://abc.com/one/p-KH83 -----> http://abc.com/one/p-KH194
On Apache it was very simple to do in .htaccess like:
Redirect 301 /one/p-SF10 http://www.abc.com/one/p-SF134
Redirect 301 /one/p-SM28 http://www.abc.com/one/p-SM28
Redirect 301 /onep-KH83 http://www.abc.com/one/p-KH194
I found one of the guides with following lines:
if ( $request_filename ~ oldpage/ ) {
rewrite ^ http://www.domain.com/newpage/? permanent;
}
My question here is do I need to create these 200 ‘if conditions’? Wouldn’t it create a huge conditional loop and overload my server?
Server configuration: I installed Nginx+php-fpm using VestCP and set the nginx template to wordpress from within VestCP which configured my nginx.conf automatically.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
You are right to want to avoid using if conditions here, luckily you can avoid them completely by doing the matching with a regex right in the rewrite directive. For example:
rewrite ^/path/to/old $scheme://$host/new/url permanent;
This blog post from Nginx themselves is a good read on the different ways to create rewites and redirects with Nginx and when to use them.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.