Running XenForo from subfolder but appear as if installed on webroot

AndyB

Well-known member
If XenForo is installed for example in the following subfolder:

Code:
http://www.example.com/forums/

and I want visitors to be able to use the forum as if I had installed XenForo on the webroot, is this possible? It would be nice if I could add a line of code to the .htaccess file in the webroot to accomplish this.
 
You can look up the apache documentation for "document root"

I use nginx and I can set any directory as document root. The directive in nginx is "root /var/web/xf2015;", this directory would then serve files for www.example.com
 
Hello,

So let me get this straight:
You saying you installed xenforo on domain.com/forums and wish people to access your site as if it were installed on domain.com?

That is not possible.


However you can apply a rewriting rule to redirect all traffic from domain.com to domain.com/forums.
That way when someone types domain.com he will be automatically redirected to domain.com/forums.

Add this to .htaccess:
RewriteRule ^$ /forums [L]


Kind regards,
George.
 
Last edited:
As mentioned, your service provider should be able to do this by changing root directory to /forums.

This config from stackoverflow could get you started with a .htaccess solution. It worked for me in a small test, but left many broken links (images,CSS,etc). They were defaulting to a subfolder that is being rewritten out.

Code:
RewriteCond %{THE_REQUEST} ^GET\ /apt/
RewriteCond %{HTTP_HOST} ^(www\.)?mysite.com$
RewriteRule ^apt/(.*) /$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^(www\.)?mysite.com$
RewriteRule !^apt/ apt%{REQUEST_URI} [L]

.htaccess hide subdirectory url after redirect
 
Last edited:
Thank you, n00bsaibot. I tried doing what you posted and the forum list shows fine but when I click into a forum I get an error.

In the end I just when ahead and moved the /forums/ contents to the web root.
 
You can use a pointer directory as webroot. If you have these directories:

/var/web/2013
/var/web/2014
/var/web/2015

... you can create a pointer directory

/var/web/live (which is your webroot)

... and point this directory to /var/web/2015

So you can upload a lot of different xenforo installations and just change the pointer directory /var/web/live to the directory you want.
 
Maybe just clone the index.php and move it to the root while keeping the other files and folders into the sub directory?
 
The stackoverflow directions work... you just need two .htaccess files to do this.

1st at the root to forward all requests to /forums/
2nd (the one posted above) in the /forums/ sub-directory to rewrite the URL

If you forgot the first .htaccess all the files will try to run from the root, where they obviously don't exist.
 
Thanks n00bsaibot.

It would be extremely helpful if you could post both .htaccess files so people will understand better.
 
Double redirects for any request will definitely make your forum a bit slower, it depends on how expensive these redirects are. Apache redirects regularly make use of regular expressions (usually when it is difficult to understand the expression, it's a regular one), that makes everything much slower.
 
As I said earlier, I ended up moving the XenForo software to the web root. I hope XenForo v2.0 will allow the software to be in a sub-folder and also will have a Home page as an option.
 
Back
Top Bottom