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

nginx help

Rob

Well-known member
#1
I have a test server running nginx and I am trying to get a copy of my site running on it.

I am currently trying to convert some ReWrite Rules over to nginx syntax and am struggling a little...

Here are two example rules:-
#Forum
RewriteRule ^forumname-73/sub-forum-name-10/$ http://www.mydomain.net/forums/international-midwifery.10/ [R=301,L]

#Forum with paging
ReWriteRule ^forumname-73/sub-forum-name-10/index([\d]+).html http://www.mydomain.net/forums/sub-forum-name.10/page-$1 [R=301,L]
I believe for first rule above, the following nginx syntax would work ok:-
rewrite ^/forumname-73/sub-forum-name-10/$ http://www.mydomain.net/forums/international-midwifery.26/ permanent last;
Not sure about using permanent AND last but anyway.... how do I do the last .htaccess rule with paging?
 

Jake Bunce

XenForo moderator
Staff member
#2
Here is the documentation:

http://wiki.nginx.org/HttpRewriteModule#rewrite

how do I do the last .htaccess rule with paging?
Probably create another rule to match the other pattern (with page numbers). Something like this:

Code:
rewrite ^/forumname-73/sub-forum-name-10/([0-9]+)/$ http://www.mydomain.net/forums/international-midwifery.26/page-$1 permanent;
This is assuming original 'page' URLs like this:

/forumname-73/sub-forum-name-10/page number here/

The regex depends on the format of the original URL.
 

Rob

Well-known member
#3
I am routing these via the Kier's redirection pages and the trouble I am getting is that showthread.php and forumdisplay.php are being appended to the path.
An old vbseo url for a thread seems to be rewritten to the same url but the latter part being swapped for showthread.php ... grrrr.... same for forums.

I need to sort this but something, somewhere is very wrong. That documentation hasn't helped much tbh.
 

Jake Bunce

XenForo moderator
Staff member
#4
What rewrite rule are you using to map the URLs to the redirect scripts? Because the examples you posted don't use those scripts.
 

Jake Bunce

XenForo moderator
Staff member
#6
Instead of ([\d]+) you might try ([0-9]+). I have found this to be necessary on some servers.

And technically you should escape the "." in ".html":

\.html

You mentioned the file names are appended to the path. I'm not quite sure what that means. But you can try using a full URL for the location. Instead of showthread.php?t=$1 use http://www.....showthread.php?t=$1. Or this might be relevant:

http://wiki.nginx.org/HttpRewriteModule#rewrite

If in the line of replacement arguments are indicated, then the rest of the request arguments are appended to them. To avoid having them appended, place a question mark as the last character:

rewrite ^/users/(.*)$ /show?user=$1? last;
 

Rob

Well-known member
#7
Ok, I have got this working, I think its because i left out the slash in front of showthread. In fact, I got rid of showthread altogether for threads since its not nessesary when a thread doesnt using paging (ie, when on page 1)...

Here are my rules for regular threads and threads with paging
Code:
#threads with paging
rewrite [^/]+/([\d]+)-.+-([\d]+).html /showthread.php?t=$1&page=$2 last;
 
#regular threads
rewrite [^/]+/([\d]+)-.+.html /threads/.$1/ permanent;
Obviously, I have my xF and old vB set to the same number of threads per page and also I think I modified Kier's script a little.