• SupportHostingSolved
  • What is in general the best aproach to redirect from domain root to forum folder

Via htaccess

RewriteEngine On
RewriteRule ^$ /Forum[L]

Or via php redirect ?

header('Location: '.$newURL.php);

Thanks a bunch in advance

  • luceos replied to this.
  • User31 and Anomalum like this.
  • NoIdeaWhatThatIs htaccess is more reliable. The header function in php can be unreliable, for instance when headers are already sent due to other errors. The htaccess works on the same level as the webserver vhost file, which is always the best solution.

    A question that comes to mind is why is the redirect needed in the first place? Usually if you install the forum in a subfolder it means you have a main website (for example, WordPress) at the root. If you're not going to use the root path for another app, why not install the forum at the root?

    Make sure you are not accidentally exposing private Flarum files if you are doing this because you had issues removing the subfolder. It's always worth a scan to be sure https://discuss.flarum.org/d/10056-migratetoflarum-lab-the-health-scanner-for-flarum

    If this is a temporary redirect while waiting for the main website to be published, using a PHP file can be easier to not forget about it when uploading the website, as removing/replacing the file will automatically remove the redirect instead of having to find where it was defined. Don't forget to use a 302 temporary redirect if that's your use case, otherwise visitors won't be able to load the main website if their browser has cached the redirect.

      4 months later

      NoIdeaWhatThatIs when you move your Flarum contents to root you have to edit your site.php index.php and config.php. You’ll also need to protect your exposed resources either via the built in nginx.conf or .htaccess. More details can here found here

        wylzn so if i move directory the folder will be vulnerable?
        My flarum (which is sitting in a subfolder) isn't actually live i've just themed it up till now. Wouldn't it be better or less complicated if i just reinstall it fresh onto root and move the plugins from the subfolder into the newly installed flarum?

          wylzn Very kind but i decided in the meantime to install flarum onto root. I "just" ( 🙄 ) had to copy+pasta all settings and theme related stuff, and redownload the plugins manually so it took me just almost 2 hours or such 😆 .

          But thanks a lot 👍