0

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?

Big McLargeHuge
  • 14,841
  • 10
  • 80
  • 108
  • Why you can't move the forum to the 'www' folder? – cvsguimaraes Apr 18 '14 at 00:48
  • Why you wouldn't? Just trying to understand what you doing man... – cvsguimaraes Apr 18 '14 at 16:06
  • Well, there are several projects in `/var/www` besides `/phalcon`. The application has many parts including forums. So `/forums` resides under `/phalcon`. Moving `/forums` to `/var/www` would make it a whole separate application, would it not? – Big McLargeHuge Apr 18 '14 at 16:17
  • @cvsguimaraes btw I wasn't trying to be rude, I just don't understand how moving the forums directory would help solve my problem. I want the URL to access the forums to be `http://localhost/phalcon/forums`. Can I accomplish that if the forums directory is not under `/var/www/phalcon/public/forums`? Is my project structure all wrong? – Big McLargeHuge Apr 18 '14 at 16:24
  • We cool :) I'm writing an answer taking in consideration what you said, hang on. – cvsguimaraes Apr 18 '14 at 16:32

1 Answers1

1

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.

cvsguimaraes
  • 12,910
  • 9
  • 49
  • 73
  • If you want the trailing slash optional to be able to access `/forums` change `!^/forums/.*$` to `!^/forums(\/||).*$` – cvsguimaraes Apr 18 '14 at 16:51
  • It's still throwing an error because it can't find the ForumsController. [This works](http://stackoverflow.com/a/1848579/1015595) - `RewriteRule ^forums($|/) - [L]` - except I can't get it to work without the trailing slash. I tried `^forums.*$`, `^forums(\/||).*$`, no dice. – Big McLargeHuge Apr 18 '14 at 18:11
  • @Koveras try this last one – cvsguimaraes Apr 18 '14 at 18:25
  • I haven't touched this project since April, but it works fine now. Actually, I used `RewriteCond %{REQUEST_URI} !^/forums.*`, which is a bit easier for me to understand. – Big McLargeHuge Sep 29 '14 at 02:38