Nginx Rewrite Rules

Chris D

XenForo developer
Staff member
Ok, thank you to everyone who suggested various hosts.

Ultimately we decided upon Nimbus hosting who so far have been excellent.

We now just need a little bit of help with setting up some nginx rewrite rules as previously we were using Apache, but these aren't as straight forward as normal rewrites.

At the same time we moved from vBulletin 4 to XenForo, we also changed our domain name from Halflife2.net to Valvetime.net.

We have two options:

A - We simply get help with rewrite rules that redirect http://www.halflife2.net/forums/* to http://www.valvetime.net/* and we let the VB4 redirect scripts (showthread.php etc) do the rest which is effectively two redirects.

B - We forget about the redirection scripts and we get help with all the rules necessary to redirect vB URLs to XenForo, e.g. http://www.halflife2.net/forums/showthread.php?t=12345 -> http://www.valvetime.net/threads/12345 etc.

Cheers guys (y)
 

Jake Bunce

XenForo moderator
Staff member
Try this (option A):

Code:
location /forums/ {
	if ($host ~* ^(www\.)?halflife2\.net$) {
		rewrite ^(.*)$ http://www.valvetime.net/$1 permanent;
	}
}
 

Arkshine

Active member
If I remember "if" in nginx is evil, what says the documentation. You can easily avoid it.
Chris, mind to share you actual nginx site config ? It will be more easy to see what line to add is appropriate.
 

Floren

Well-known member
Try this (option A):

Code:
location /forums/ {
if ($host ~* ^(www\.)?halflife2\.net$) {
rewrite ^(.*)$ http://www.valvetime.net/$1 permanent;
}
}
IF is evil, this is the proper way:
Code:
server {
	listen		192.168.1.8:80;
	server_name	halflife2.net *.halflife2.net;
	rewrite ^	http://www.valvetime.net$request_uri? permanent;
}
Then you do the proper redirects on the new server configuration.
You don't need the redirect script provided by XenForo devs, if you use nginx.

Example:
http://www.thcfarmer.com/forums/f9/
http://www.thcfarmer.com/forums/f36/hi-all-28387/
 
It took me about a day to really start understanding the config format and how it works and figure out how I needed my config oriented. Once I did that, it was pretty simple, and I'm pretty confident about using it now. If you're not technically-oriented, Apache might be the better option for you - more information for setting it up and a larger community, I believe. That said, nginx is cool, and apparently the way to power larger boards. I like it.
 

Mr. Goodie2Shoes

Well-known member
I actually haven't played with it that much... is there any good reference available... I googled a lot but so far, no luck...
 
Top