Redirection Scripts for Invision IP Forums and Gallery

Redirection Scripts for Invision IP Forums and Gallery 2.0.2

No permission to download

XenForo

Company info
Staff member
XenForo submitted a new resource:

Redirection Scripts for Invision Forums 3.x - Redirects Invision URLs to XenForo for SEO benefits

If you have imported your IPB 3.x database into XenForo, you can automatically redirect all traffic destined for your IPB content to its new location within XenForo.

All that is required is that you unzip these files and place them in the directory in which your IPB files resided. The included .htaccess file will take care of redirecting calls to IPB into to the ips2xf.php file, which will in turn redirect traffic to the appropriate traffic to XenForo.

Any requests of the old URLs...

Read more about this resource...
 
The redirections are done via htaccess rules, so it should generally work as long as the particular URL scheme is the same (which I believe it is).
 
My old URL is:
http://www.foroiphone.com/foros/tema/120181-post-venta-k-tuin/
My IPB4 was installed in the root as my XF
I don´t have edited the 301config

My htaccess:
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 405 default
ErrorDocument 406 default
ErrorDocument 500 default
ErrorDocument 501 default
ErrorDocument 503 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 /xenforo

    #    This line may be needed to enable WebDAV editing with PHP as a CGI.
    #RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -l [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^.*$ - [NC,L]
    RewriteRule ^(data/|js/|styles/|install/|favicon\.ico|crossdomain\.xml|robots\.txt) - [NC,L]
    RewriteRule ^.*$ index.php [NC,L]

    # 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>
 
Last edited:
@Mike
I had IPB in /forums/ and now my XF in the root. Do I need to change anything besides the 301config?

IPB: https://www.domain.com/forums/forum/36-category-name/
Xenforo: https://www.domain.com/forums/category-name.36/

I'm also using NGINX:

location / {
index index.php index.html index.htm;
#try_files $uri $uri/ /index.php?$uri&$args;
if ($uri ~* forums/(topic|forum|user)/) {
rewrite ^ forums/ips2xf.php? last;
}

if ($args ~* (^|&)show(topic|forum|user)=) {
rewrite ^ forums/ips2xf.php? last;
}

if ($args ~* ^/(topic|forum|user)/) {
rewrite ^ forums/ips2xf.php? last;
}
try_files $uri $uri/ /index.php?$uri&$args;
include /usr/local/nginx/conf/503include-only.conf;
}
 
Last edited:
Getting a php error regularly. Is this also a function which must be compiled into php?
Code:
[22-Feb-2021 15:56:05 Europe/Amsterdam] PHP Fatal error:  Uncaught Error: Call to undefined function file_exists() in /home/user/domains/mydomain.org/public_html/ips2xf.php:4
Stack trace:
#0 /home/user/domains/mydomain.org/public_html/css.php(6): XF::start('/home/user/do...')
#1 {main}
  thrown in /home/user/domains/mydomain.org/public_html/src/XF.php on line 71
 
I migrated from IPB 4.5 with IPGallery. If you're in a similar position and were using friendly URLs with IPB, here are the changes that will make it so you can 301 redirect old URLs to existing ones:

.htaccess
Apache config:
#Find:
RewriteCond %{PATH_INFO} ^/(topic|forum|user)/

#Replace:
RewriteCond %{PATH_INFO} ^/(topic|forum|user)/ [OR]
RewriteCond %{REQUEST_URI} ^/(gallery/image|gallery/album|gallery/category)/

301config.php
PHP:
//Define $fileDir and uncomment

//Define IMPORT_LOG_TABLE with the appropriate name of your import log of the gallery and uncomment

ips2xf.php
PHP:
//Find
preg_match('#/(?P<type>topic|forum|user)/(?P<id>\d+)#s', $_SERVER['REQUEST_URI'], $input);

//Replace
preg_match('#/(?P<type>topic|forum|user|gallery/image|gallery/album|gallery/category)/(?P<id>\d+)#s', $_SERVER['REQUEST_URI'], $input);

//Find
                case 'user':
                {
                        $newId = $log->lookupId('user', $input['id']);
                        if ($newId)
                        {
                                $target = $router->buildLink('canonical:members', ['user_id' => $newId]);
                        }
                        break;
                }

//Add
                case 'gallery/album':
                {
                        $newId = $log->lookupId('xfmg_album', $input['id']);
                        if ($newId)
                        {
                                $target = $router->buildLink('canonical:media/albums', ['album_id' => $newId]);
                        }
                        break;
                }
                case 'gallery/image':
                {
                        $newId = $log->lookupId('xfmg_media', $input['id']);
                        if ($newId)
                        {
                                $target = $router->buildLink('canonical:media', ['media_id' => $newId]);
                        }
                        break;
                }
                case 'gallery/category':
                {
                        $newId = $log->lookupId('xfmg_category', $input['id']);
                        if ($newId)
                        {
                                $target = $router->buildLink('canonical:media/categories', ['category_id' => $newId]);
                        }
                        break;
                }

Unfortunately I'm not too savvy with PHP. I'm not sure how to have it load both import logs to be used by the redirection script. I got this far banging my head against the wall. If anyone could point me in the right direction for that, would be happy to post the rest of the code necessary to make this work for both.
 
I beat my head against the wall a bit longer and found a solution to get it to work for both. I copied most of the code from ips2xf.php to another file (I called mine ips2mg.php) and used the code posted above. Also I defined the import log table at the top in line 17. Do the same for the original ips2xf.php for your forum import table.

Then comment out the import log definition in 301config.php. I recommend defining $fileDir even if you didn't change folders.

In .htaccess, create a separate rule just for gallery links to go to the new ips2mg.php below the rewrite rules for ips2xf.php like so:
Apache config:
RewriteCond %{REQUEST_URI} ^/(gallery/image|gallery/album|gallery/category)/
RewriteRule ^.*$ ips2mg.php [NC,L]

I know this doesn't cover 100% of all links and I'm sure it could be done with cleaner code, but it covers the majority of it. I hope this helps others who wanted to avoid the hit of losing a bunch of SEO from the migration.
 
Last edited:
I had IPB3, am now on XF 2.2

I put these 3 files in root (the .htaccess overwrites the other one)... and this does not work. Nothing is redirected.
 
Last edited:
Top Bottom