Question

I'm trying to add XenForo to my Phalcon application. The project is structured like this:

www/
    phalcon/
        app/
            controllers/
                AccountController.php
            views/
                account
                    login.phtml
        public/
            forums/    <-- XenForo installation
            .htaccess
            index.php
        .htaccess

The file at www/phalcon/.htaccess looks like this:

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteRule  ^$ public/    [L]
    RewriteRule  (.*) public/$1 [L]
</IfModule>

And the file at www/phalcon/public/.htaccess looks like this:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php?_url=/$1 [QSA,L]
</IfModule>

I added a view at www/phalcon/app/views/account/login with a form that posts to the XenForo login script, which is at http://localhost/phalcon/forums/login:

<?php echo $this->tag->form('forums/login'); ?>

    <p>
        <label for="name-email">Name or email:</label>
        <?php echo $this->tag->textField('login'); ?>
    </p>

    <p>
        <label for="password">Password</label>
        <?php echo $this->tag->passwordField('password'); ?>
    </p>

    <p>
        <?php echo $this->tag->submitButton('Login'); ?>
    </p>

<?php echo $this->tag->endForm(); ?>

Posting the form threw an error because I don't have a ForumsController:

PhalconException: ForumsController handler class cannot be loaded

So I modified the file at www/phalcon/public/.htaccess to this:

<IfModule mod_rewrite.c>
    RewriteEngine On

    RewriteRule ^(forums)($|/) - [L]

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php?_url=/$1 [QSA,L]
</IfModule>

This causes Phalcon to ignore any route that starts with forums. However, now I get a 404 when I post the form:

The requested URL /phalcon/public/forums/login was not found on this server.

I thought XenForo would take over the routing at this point but apparently not. What do I need to do to get Phalcon and XenForo to play nice?

Was it helpful?

Solution

But XenForo isn't a whole separate application? I understand what you want, but take a deep breath and think if you really need it. IMHO you're complicating thing for yourself. What if XenForo use some magic URLs that points to non-existent files?!

I'm not able to point all possible complications, but surely there will be some of them, and you can avoid this by simple put XenForo installation anywhere than the folder that Phalcon uses for their own assets. Each project has their conventions, I'm just have a bad felling about this :)

Here's my suggestion: You can remain with XenForo inside of 'phalcon' folder but move it outside the 'public' folder and add some rewrite for this folder in the main .htaccess:

<IfModule mod_rewrite.c>
    RewriteEngine on

    RewriteRule  ^$ public/    [L]

    RewriteCond %{REQUEST_URI} !^/forums(\/.*$|$)
    RewriteRule  (.*) public/$1 [L]
</IfModule>

Basicaly the same thing you're doing before, but in a more "safe" place.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top