Apache to nginx rewrite rule

dbembibre

Active member
I convert my apache rewrite rule to nginx, in first place know if is correct, i guess that yes.

Apache
Code:
RewriteRule ^[^/]+/.+-([0-9]+)/ /threads/$1/? [R=301,L]

nginx

Code:
location / {
  rewrite ^/[^/]+/.+-([0-9]+)/ /threads/$1/? redirect;
}

From a SEO perspective is better a redirect or a permant instruction, i want that google crawl the destination URL instead of origin url ??

Code:
location / {
  rewrite ^/[^/]+/.+-([0-9]+)/ /threads/$1/? redirect;
}

OR

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


Thanks to all :)
 
You are killing your server with those regexes. :)
Post several real path examples you are trying to rewrite (from > to).
 
You are killing your server with those regexes. :)
Post several real path examples you are trying to rewrite (from > to).

This that i need to translate

My original vBSEO URLs look like this:
f7=forum id;
usar-un-polimetro-tester-finalizado = post title
409892 = thread id.
www.mysite.com/f7/usar-un-polimetro-tester-finalizado-409892/
the XenForo URL have the following format:
www.mysite.com/threads/usar-un-polimetro-tester-finalizado.409892/
 
Code:
location /f7 {
    location ~ ^/f7/.+-([\d]+)/$ {
        return 301 /threads/$1/;
    }
}
Yes you will repeat that combination for as many forum id's you have, so you avoid crazy rewrites like the one you posted above. Use the same technique for pagination, posts, etc. Don't complain about repetitive stuff, if you want performance. You might be tempted to do something like:
Code:
location ~ ^/f[\d]+/.+-([\d]+)/$ {
Don't. Last time I talked with Igor Sysoev, his config file was 87KB.
The key element of that config part is:
Code:
location /f7 {
If you think you might get lost, just create a separate file with all your rules and use the include directive to append the file to Nginx configuration. As a bonus, using this technique, you will not need the php files produced by Kier and Mike to rewrite vBulletin format to XenForo.
 
Last edited:
Code:
location /f7 {
    location ~ ^/f7/.+-([\d]+)/$ {
        return 301 /threads/$1/;
    }
}
Yes you will repeat that combination for as many forum id's you have, so you avoid crazy rewrites like the one you posted above. Use the same technique for pagination, posts, etc. Don't complain about repetitive stuff, if you want performance. You might be tempted to do something like:
Code:
location ~ ^/f[\d]+/.+-([\d]+)/$ {
Don't. Last time I talked with Igor Sysoev, his config file was 87KB.
The key element of that config part is:
Code:
location /f7 {
If you think you might get lost, just create a separate file with all your rules and use the include directive to append the file to Nginx configuration. As a bonus, using this technique, you will not need the php files produced by Kier and Mike to rewrite vBulletin format to XenForo.


As always @Floren (and you help me that one more time from my vbseo times) thanks a lot mate, i start with a location for every forum that i have.
 
Back
Top Bottom