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

Running XenForo from subfolder but appear as if installed on webroot

Discussion in 'Server Configuration and Hosting' started by AndyB, Aug 8, 2015.

  1. AndyB

    AndyB Well-Known Member

    If XenForo is installed for example in the following subfolder:

    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.
    gldtn likes this.
  2. Marcus

    Marcus Well-Known Member

    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
  3. Set3sh

    Set3sh Active Member


    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,
    Last edited: Aug 8, 2015
  4. n00bsaibot

    n00bsaibot Well-Known Member

    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.

    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: Aug 8, 2015
  5. AndyB

    AndyB Well-Known Member

    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.
  6. Marcus

    Marcus Well-Known Member

    You can use a pointer directory as webroot. If you have these directories:


    ... 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.
  7. Nicky Vermeersch

    Nicky Vermeersch Active Member

    Isn't this why there are route filters in xenforo?

    Find route: forums/
    Replace with: /
  8. batpool52!

    batpool52! Well-Known Member

    Maybe just clone the index.php and move it to the root while keeping the other files and folders into the sub directory?
  9. Brogan

    Brogan XenForo Moderator Staff Member

    You can't globally remove a route using a route filter.
    Nicky Vermeersch likes this.
  10. n00bsaibot

    n00bsaibot Well-Known Member

    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.
  11. AndyB

    AndyB Well-Known Member

    Thanks n00bsaibot.

    It would be extremely helpful if you could post both .htaccess files so people will understand better.
  12. Marcus

    Marcus Well-Known Member

    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.
  13. AndyB

    AndyB Well-Known Member

    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.
    viper357 likes this.
  14. Brogan

    Brogan XenForo Moderator Staff Member

    It does now.

    This very site does exactly that.

Share This Page