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

XF 2.0 Redirect from /forums/ to root

Mr Lucky

Well-known member
#1
I have one forum that is installed in /forums/ but I now need to move it to the root.

Normally I would use this in .htaccess
Code:
RewriteRule ^forums/(.*)$ /$1 [R=301,NC,L]
but of course that messes with the xenForo path for the forum list and the forums themeselves, and so the Forums tab just gets redirected to the home page.

I have a route filter changing forums/ to forum/ . This allows the forum navigation tab to work, but any external inbound links with /forums/ don't work


(Obviously a similar redirect works fine for my other forum that is redirected out of /community/ but of course that does not conflict with the xenForo /forums/ URL)

Does anyone please know a way round this or are we stuck forever with the xenforo installed in /forums?

Thanks
 

Mike

XenForo developer
Staff member
#2
Essentially, you would need to redirect specific sub-routes that don't conflict, so things like forums/forums/ and forums/threads/. This won't cover every URL -- you'd need to list all the ones you want -- but it should cover most of the common cases.
 

Mr Lucky

Well-known member
#3
Thanks that makes sense. So I'd probably only need:

forums/forums/ to forums/
forums/threads/ to threads/
forums/resources/ to resources/

to cover most common eventualities of external links/bookmarks.

My problem now then is finding the .htaccess to do that, nothing I've tried works, e.g:

Code:
RewriteRule ^forums/forums/(.*)$ /forums/$1 [R=301,NC,L]
does anyone know what I'd need?

Thanks
 

Mike

XenForo developer
Staff member
#4
I think that'd work, though make sure you're trying with a fresh URL each time to avoid browser caching issues. Beyond that, make sure you've removed the "general" rule, as the first match will be triggered.
 

Mike

XenForo developer
Staff member
#6
I don't see why it wouldn't off hand. Where does it redirect you to? Do you have an example URL we can test?
 

Mr Lucky

Well-known member
#7
OK, it is working now. maybe it just needed you to say it should. Redirects are voodoo IMO. Or it was cache thing. (I blame most things on cache)

Thanks.
 

Sim

Well-known member
#8
Redirects are voodoo IMO. Or it was cache thing. (I blame most things on cache)
Don't forget that most browsers now aggressively cache 301 redirects - even ignoring Ctrl-F5 and such and ignoring any changes you make to your code or web server config.

You basically need to clear the cache completely to get rid of them - or while testing, use a 302 redirect and then change it to 301 once you're happy it works.

I find testing redirects in incognito mode generally works better - I believe the cache is flushed when the incognito browser is closed.
 

Mr Lucky

Well-known member
#9
Don't forget that most browsers now aggressively cache 301 redirects - even ignoring Ctrl-F5 and such and ignoring any changes you make to your code or web server config.

You basically need to clear the cache completely to get rid of them - or while testing, use a 302 redirect and then change it to 301 once you're happy it works.

I find testing redirects in incognito mode generally works better - I believe the cache is flushed when the incognito browser is closed.
Thanks, this sounds useful