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

Trouble creating nginx rewrite rules for old vbseo urls

Discussion in 'Troubleshooting and Problems' started by whyweprotest, Jan 7, 2011.

  1. whyweprotest

    whyweprotest Well-Known Member

    Hi all,

    We are in the process of migrating from vbulletin 3.8.x to xenforo. Obviously we would like to redirect our many existing links to their new home using the 301 redirect script that kier provided and the XFSEO recipe tool from Shadab. However, since it is all written for apache (and since I suck at nginx rewrite rules it would seem) I am having some difficulty which I am hoping someones ginormous brain can help with!

    vB showthread format: http://forums.whyweprotest.net/233-website-issues-requests/wiki-down-73789/
    XF showthread format: http://forums.whyweprotest.net/threads/the-wiki-is-down.65509/

    vB forumdisplay format: http://forums.whyweprotest.net/233-website-issues-requests/
    XF forumdisplay format: http://forums.whyweprotest.net/forums/website-issues-and-requests.253/

     if (!-e $request_filename) {
         rewrite [0-9a-zA-Z\-]/[0-9a-zA-Z\-]-([0-9])/([0-9])/ /showthread.php?t=$1&page=$2 last;
         rewrite [0-9a-zA-Z\-]/[0-9a-zA-Z\-]-([0-9])/ /showthread.php?t=$1 last;
         rewrite ([0-9])-[0-9a-zA-Z\-]/([0-9])/ /forumdisplay.php?f=$1&page=$2 last;
         rewrite ([0-9])-[0-9a-zA-Z\-]/ /forumdisplay.php?f=$1 last;
         rewrite ^(.*)$ /index.php last;
    The showthread method will redirect to the proper thread, however it never goes to the correct page if given. I'm sure I'm missing something, but when I looked at the showthread.php created by kier, I did not see anything in there to handle the &page var, just a postid.

    The forumdisplay option is not working for me at all though.. and I believe I am failing in creating the rule for it. I'm a bit confused because it FEELS like I'm using the same methodology that worked for showthread, but... nope.

    Has anyone faced similar issues (and succeeded) with trying to 301 in nginx?
    JamesBrown likes this.
  2. Brogan

    Brogan XenForo Moderator Staff Member

  3. whyweprotest

    whyweprotest Well-Known Member

    Oh, should have included this earlier. Here is the apache style rewrite recipe for my seo setup:

    RewriteEngine on RewriteRule [\d]+-[^/]+/.+-([\d]+)/([\d]+)/ showthread.php?t=$1&page=$2 [NC,L]

    RewriteRule [\d]+-[^/]+/.+-([\d]+)/ showthread.php?t=$1 [NC,L]

    RewriteRule ([\d]+)-[^/]+/([\d]+)/ forumdisplay.php?f=$1&page=$2 [NC,L]

    RewriteRule ([\d]+)-[^/]+/ forumdisplay.php?f=$1 [NC,L]
    Blandt likes this.
  4. Luke F

    Luke F Well-Known Member

    Put a + after every ]
    whyweprotest likes this.
  5. whyweprotest

    whyweprotest Well-Known Member

    Darkimmortal: I love you and your big brain. That is working for the most part, but it is still failing to pass to the right page.

    eg, http://forums.whyweprotest.net/233-website-issues-requests/ goes to the forum category page 1, http://forums.whyweprotest.net/233-website-issues-requests/2/ does not go to page 2, but just to page 1. Do you suspect that is an issue with the rewrite, or with kier's 3.8 redirect script?

    Again, thank you.. and for those playing along at home, this is what I have that is mostly working:

    if (!-e $request_filename) {
         rewrite [0-9a-zA-Z\-]+/[0-9a-zA-Z\-]+-([0-9]+)/([0-9]+)/ /showthread.php?t=$1&page=$2 last;
         rewrite [0-9a-zA-Z\-]+/[0-9a-zA-Z\-]+-([0-9]+)/ /showthread.php?t=$1 last;
         rewrite ([0-9]+)-[0-9a-zA-Z\-]+/([0-9]+)/ /forumdisplay.php?f=$1&page=$2 last;
         rewrite ([0-9]+)-[0-9a-zA-Z\-]+/ /forumdisplay.php?f=$1 last;
         rewrite ^(.*)$ /index.php last;
  6. Blandt

    Blandt Well-Known Member

    ...hmmm complicated affair :D

    Did you even get this to work under apache ?

    To zero in on the problem get this to work on Apache, then give us the .htaccess .. I think the problem lies with the redirect script redirecting the vB pretty URLs
  7. Luke F

    Luke F Well-Known Member

    That's down to a lack of support in the redirect script. Not really much of a loss though - how many places are going to have links to anything other than page 1 of a forum?

Share This Page