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

IP.Board import, how to get redirects working under nginx

Discussion in 'Installation, Upgrade, and Import Support' started by Jesepi, Aug 20, 2011.

  1. Jesepi

    Jesepi Well-Known Member

    Since .htaccess files are not used by nginx, the file included with the ip.board redirect script does not work. Can anyone re-write these to work with nginx?

    Code:
    #    Mod_security can interfere with uploading of content such as attachments. If you
    #    cannot attach files, remove the "#" from the lines below.
    #<IfModule mod_security.c>
    #    SecFilterEngine Off
    #    SecFilterScanPOST Off
    #</IfModule>
    
    ErrorDocument 401 default
    ErrorDocument 403 default
    ErrorDocument 404 default
    ErrorDocument 500 default
    
    <IfModule mod_rewrite.c>
        RewriteEngine On
     
        #    If you are having problems with the rewrite rules, remove the "#" from the
        #    line that begins "RewriteBase" below. You will also have to change the path
        #    of the rewrite to reflect the path to your XenForo installation.
        #RewriteBase /ip.board
    
        # IPS Rewrite Rules
        RewriteCond %{REQUEST_URI} /(topic|forum|user)/ [OR]
        RewriteCond %{QUERY_STRING} (^|&)show(topic|forum|user)= [OR]
        RewriteCond %{QUERY_STRING} ^/(topic|forum|user)/ [OR]
        RewriteCond %{PATH_INFO} ^/(topic|forum|user)/
        RewriteRule ^.*$ ips2xf.php [NC,L]
    
        RewriteCond %{REQUEST_FILENAME} -f [OR]
        RewriteCond %{REQUEST_FILENAME} -l [OR]
        RewriteCond %{REQUEST_FILENAME} -d
        RewriteRule ^.*$ - [NC,L]
    
        RewriteRule ^(data|js|styles|install) - [NC,L]
        RewriteRule ^.*$ index.php [NC,L]
    </IfModule>
    
    Also, is there a particular reason the vbullein redirect script uses several php files with no htaccess, while this one only uses a 2 and an htaccess file?
     
  2. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    What you have there is a default XenForo htaccess file plus IPB rewrites. The nginx version of the default htaccess file is here:

    http://xenforo.com/help/friendly-urls/

    Code:
    location /xf/ {
    	try_files $uri $uri/ /xf/index.php?$uri&$args;
    	index index.php index.html;
    }
    
    location /xf/internal_data/ {
    	internal;
    }
    location /xf/library/ {
           internal;
    }
    
    location ~ \.php$ {
    	fastcgi_pass    127.0.0.1:9000;
    	fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;
    	include         fastcgi_params;
    }
    
    I started learning about nginx configs yesterday when I saw this thread. I came up with some rules for the IPB redirects, but I don't have access to a nginx server or IPB import to test this:

    Code:
    location /ipb/ {
    	if ($uri ~* /(topic|forum|user)/) {
    		rewrite ^ /ipb/ips2xf.php? last;
    	}
    
    	if ($args ~* (^|&)show(topic|forum|user)=) {
    		rewrite ^ /ipb/ips2xf.php? last;
    	}
    
    	if ($args ~* ^/(topic|forum|user)/) {
    		rewrite ^ /ipb/ips2xf.php? last;
    	}
    }
    
    You will need to change the /ipb/ path appropriately.

    I can't find a nginx equivalent for PATH_INFO.

    Keep in mind that this is untested and I have never done it before. :cautious:

    For reference:
    http://wiki.nginx.org/NginxHttpCoreModule#location
    http://wiki.nginx.org/NginxHttpCoreModule#try_files
    http://wiki.nginx.org/HttpRewriteModule#rewrite
    http://wiki.nginx.org/HttpRewriteModule#if
    http://wiki.nginx.org/IfIsEvil
    http://wiki.nginx.org/HttpCoreModule#Variables
     
    denam, 3dsoft, Marcus and 2 others like this.
  3. Jesepi

    Jesepi Well-Known Member

    Thanks, that worked nicely.
     
    Jake Bunce likes this.
  4. Lost

    Lost Well-Known Member

    Works great for me too. One question though, is it possible to redirect the forum index page as well? I can still browse to my old forum index page and I want to automatically redirect it to my new forum index page.
     
  5. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    Try this:

    Code:
    location /ipb/ {
    	if ($uri ~* /(topic|forum|user)/) {
    		rewrite ^ /ipb/ips2xf.php? last;
    	}
    
    	if ($args ~* (^|&)show(topic|forum|user)=) {
    		rewrite ^ /ipb/ips2xf.php? last;
    	}
    
    	if ($args ~* ^/(topic|forum|user)/) {
    		rewrite ^ /ipb/ips2xf.php? last;
    	}
    
    	if ($uri ~* ^/ipb/$) {
    		rewrite ^ /ipb/ips2xf.php? last;
    	}
    }
    
    You need to specify the exact URI for the index page. If there is an "index.php" on the old forum index then it would be:

    Code:
    location /ipb/ {
    	if ($uri ~* /(topic|forum|user)/) {
    		rewrite ^ /ipb/ips2xf.php? last;
    	}
    
    	if ($args ~* (^|&)show(topic|forum|user)=) {
    		rewrite ^ /ipb/ips2xf.php? last;
    	}
    
    	if ($args ~* ^/(topic|forum|user)/) {
    		rewrite ^ /ipb/ips2xf.php? last;
    	}
    
    	if ($uri ~* ^/ipb/index\.php$) {
    		rewrite ^ /ipb/ips2xf.php? last;
    	}
    }
    
    That will match the exact location and send it to the redirect script (which will redirect to the index page in XF).
     
    Lost likes this.
  6. Lost

    Lost Well-Known Member

    Thank you very much Jake. Your first example worked like a charm!
     

Share This Page