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

XF 1.4 I moved the XenForo install folder and now lots of links are broken

Lone Wolf

Well-known member
#1
I recently moved my XenForo forum to a new server, in the process I moved the installation from /forums to /root

I also had the route changer by @Jake Bunce installed before and now lots of links both internal and incoming are resolving as errors. I have a few examples below...

Individual Forums

https://www.mydomain.com/forums/view/main_forum/ - old
https://www.mydomain.com/forums/main_forum/ - new

Individual Threads


https://www.mydomain.com/forums/threads/thread-one/ - old
https://www.mydomain.com/threads/thread-one/ - new


What's the best way have the incoming links redirect to the new structure and is there a way to change any find and replace any links inside the forum itself.
 
#2
There is a great php script for performing mass changes that might work for you. (It has saved my sanity many times when moving WP sites and should work for your xenforo database too... However, if you do use this, backup your database first!
Get The Script Here.

Good luck!
 

Jake Bunce

XenForo moderator
Staff member
#3
Use route filters to change the 'forums' route to 'view' (like before). Then remove the old /forums directory. Then add these rules to the top of the .htaccess file in your web root (XF's .htaccess file) to redirect all old traffic:

Code:
RewriteEngine on

RewriteRule ^forums/(.*)$ /$1 [R=301,L]
 

Lone Wolf

Well-known member
#4
Use route filters to change the 'forums' route to 'view' (like before). Then remove the old /forums directory. Then add these rules to the top of the .htaccess file in your web root (XF's .htaccess file) to redirect all old traffic:

Code:
RewriteEngine on

RewriteRule ^forums/(.*)$ /$1 [R=301,L]
I dont want to change the forums route to view. I'd like to keep the new URLS as they are and just have the old URLs direct to the new ones.
 

Jake Bunce

XenForo moderator
Staff member
#5
I dont want to change the forums route to view. I'd like to keep the new URLS as they are and just have the old URLs direct to the new ones.
That is difficult due to the route / directory conflict.

Try this:

Code:
RewriteEngine on

RewriteRule ^forums/view/(.+)$ /forums/$1 [R=301,L]
RewriteRule ^forums/(threads|attachments|members)/(.*)$ /$1/$2 [R=301,L]
To avoid possible conflicts you need to manually list all routes you want to redirect. And the 'view' route has its own rule.
 

Lone Wolf

Well-known member
#6
That is difficult due to the route / directory conflict.

Try this:

Code:
RewriteEngine on

RewriteRule ^forums/view/(.+)$ /forums/$1 [R=301,L]
RewriteRule ^forums/(threads|attachments|members)/(.*)$ /$1/$2 [R=301,L]
To avoid possible conflicts you need to manually list all routes you want to redirect. And the 'view' route has its own rule.
So I put this in the .htaccess file...

Code:
RewriteEngine on

RewriteRule ^forums/view/(.+)$ /forums/$1 [R=301,L]
RewriteRule ^forums/threads/(.*)$ /$1/$2 [R=301,L
RewriteRule ^forums/attachments/(.*)$ /$1/$2 [R=301,L
RewriteRule ^forums/members/(.*)$ /$1/$2 [R=301,L
[/code]
 

Jake Bunce

XenForo moderator
Staff member
#7
So I put this in the .htaccess file...

Code:
RewriteEngine on

RewriteRule ^forums/view/(.+)$ /forums/$1 [R=301,L]
RewriteRule ^forums/threads/(.*)$ /$1/$2 [R=301,L
RewriteRule ^forums/attachments/(.*)$ /$1/$2 [R=301,L
RewriteRule ^forums/members/(.*)$ /$1/$2 [R=301,L
[/code]
Code:
Use my exact code.  But expand on the red part to specify as many routes as you want.
 

Lone Wolf

Well-known member
#8
Use my exact code. But expand on the red part to specify as many routes as you want.
Oh right, I thought you meant use only the red options I want on a separate line. Thanks for that Jake, that's working now.

Whilst I have you here do you know how I can make a page with a php callback and then execute the following code in the callback...

Code:
XenForo_Application::setSimpleCacheData('mostUsers', 1386);
 

Jake Bunce

XenForo moderator
Staff member
#9
Oh right, I thought you meant use only the red options I want on a separate line. Thanks for that Jake, that's working now.

Whilst I have you here do you know how I can make a page with a php callback and then execute the following code in the callback...

Code:
XenForo_Application::setSimpleCacheData('mostUsers', 1386);
A new page or an existing page? Triggered by a specific action?
 

Lone Wolf

Well-known member
#10
A new page or an existing page? Triggered by a specific action?
I moved my old forum into a new XF database and that reset the most users online number from 1,386 back to 0 and I just want to set it back to the that number again. Jaxel said I cold do it like this by settn gup a new page and executing a PHP callback in it...

https://xenforo.com/community/threa...a-2-portal-pro-paid.89112/page-78#post-938158

But I dont know what any of that means. I know you're good with this stuff.
 

Jake Bunce

XenForo moderator
Staff member
#11
I moved my old forum into a new XF database and that reset the most users online number from 1,386 back to 0 and I just want to set it back to the that number again. Jaxel said I cold do it like this by settn gup a new page and executing a PHP callback in it...

https://xenforo.com/community/threa...a-2-portal-pro-paid.89112/page-78#post-938158

But I dont know what any of that means. I know you're good with this stuff.
To run it one time, use this script which includes that code. Upload it to your xf directory and visit it in your browser.
 

Attachments