1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Apache to nginx rewrite rule

Discussion in 'Server Configuration and Hosting' started by dbembibre, Aug 8, 2013.

  1. dbembibre

    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 :)
     
  2. Floren

    Floren Well-Known Member

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

    dbembibre Active Member

    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/
     
  4. Floren

    Floren Well-Known Member

    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: Aug 10, 2013
    dbembibre and p4guru like this.
  5. dbembibre

    dbembibre Active Member


    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.
     

Share This Page