0

I moved to a new software and now need to catch the old urls and rewrite them to the new ones.

Here is an example:

Old url: http://www.religiousforums.com/forum/neopagan-revival-religions-dir/19088-druid-horoscope-whats-your-sign.html New url: https://www.religiousforums.com/threads/druid-horoscope-whats-your-sign.19088/

I tried this but it does not work:

    location ~* ^/forum/[^/]+/[0-9]+-[^\.]+\.html$ {
            rewrite [^/]+/([0-9]+)-[^\.]+\.html$ /threads/$1/ last;
    }

What am I missing here? I only need the id in the new url. The text is not important.

1 Answer 1

2

Update : not clear what you want to do

If you mean you want to serve from both URLs the same content, then you are doing content duplication and it's a very bad idea. Now to redirect correctly from old URLs to the new ones, you must set this up :

location ~* ^/forum/[^/]+/([0-9]+)-([^.]+)\.html$ {
    return /threads/$2.$1 permanent;
}

Or simply put this in a common location block :

location /forum {
    rewrite ^/forum/[^/]+/([0-9]+)-([^.]+)\.html$ /threads/$2.$1 permanent;
}

Edit: This worked:

location /forum/ {
    rewrite ^/forum/[^/]+/([0-9]+)-([^.]+)\.html$ /threads/$1/ permanent;
}
3
  • This still does not work unfortunately. Your rule is live on the url above. Oct 31, 2014 at 20:51
  • @BamaStangGuy see updated answer. Oct 31, 2014 at 21:21
  • Second location works perfect with location /forum/ { rewrite ^/forum/[^/]+/([0-9]+)-([^.]+)\.html$ /threads/$1/ permanent; } Nov 3, 2014 at 0:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .