0

I am trying the following steps to my old urls before redirecting them:

1) Rewrite all urls inside a folder by replacing underscores to hyphens

2) Remove the old folder name

3) Try the new urls in multiple url locations to see whichever exists

I've got something like this and couldnt get it to work properly. Is this wrong?

location  ^~ /old-folder/ {

  #Change Underscores to Hiphens
  rewrite ^([^_]*)_([^_]*)_([^_]*)_([^_]*)_(.*)$ $1-$2-$3-$4-$5;
  rewrite ^([^_]*)_([^_]*)_(.*)$ $1-$2-$3;
  rewrite ^([^_]*)_(.*)$ $1-$2;

  #Remove Folder Name
  rewrite ^/old-folder/(.*)$ $1 last;

  # Try multiple locations whichever exists
  try_files /car-articles/$uri /bike-articles/$uri /index.php?$args;

}

I am absolutely new to rewrites and expressions and I could be way off. Can someone please take a look and point me in the right direction plz...

Neel
  • 1,441
  • 7
  • 21
  • 35
  • 1
    You are probably better off with `rewrite ^ handle-old-urls.php` and implementing whatever always-ends-in-a-301-redirect logic (or a 410) you want in that php file. Otherwise requests for old urls that can be corrected (search results) will continue to use the old/wrong url. – AD7six Jan 10 '15 at 11:10
  • yeah.. that seems like a simpler and uncomplicated solution. I will do that.. – Neel Jan 10 '15 at 12:27

0 Answers0