Laravel 4路由过去索引页面不适用于webfaction

I am trying to use WebFactions to host my website built with Laravel 4. I have been successful in following tutorials like this: http://euantor.com/using-laravel-with-webfaction/

The index page loads perfectly, but there seems to be a problem with any other page that I link to, giving a 500 error (suggesting that routes.php isn't working somehow).

Looking into things, it seems that I need to change the httpd.conf for the apache server, which I do not have access to on webfactions. I have tried using both .htaccess files offered by laravel (the default one it ships with, as well as this one):

Options +FollowSymLinks
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

But this also didn't seem to solve the problem. Does anyone know of a way to get Laravel 4 working on webfactions so that further routes past the index page works?

First of all, you do not need to change httpd.conf of your virtual host to make Laravel function properly.

Based on the limited amount of information that you have provided, it is impossible to tell what is wrong with your configuration. However, I can provide you with a working example configuration from my web sites at Webfaction (not Webfactions).

Directory structure

/home/myuser
|--> webapps
|  --> mysite  (This is your public web directory)
|--> laravelapps
   --> mysite  (Laravel installation, incl. routes.php)
     --> app
       --> models
       --> views
       --> etc.

For the sake of security, you should have separate folders for web content and Laravel files. In other words, do not place Laravel files and configurations under your public web directory.

Web directory

Put any file that needs to be fetched via HTTP protocol into this directory: webapps/mysite. For example, create sub-directories css, js, images and so on.

Also make sure that you have two Laravel files in the root of your web directory:

  • .htaccess
  • index.php

.htaccess.php at your web directory

<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>

What this does is to redirect all your Laravel requests to index.php. For a more detailed description of the lines, check this answer regarding a very similar .htaccess: This is the .htaccess code in WordPress. Can someone explain how it works?

index.php at your web directory

There are two important entries in this file. First one is within section Register The Auto Loader. Make sure that you have something like this (can be also a relative path):

require '/home/myuser/laravelapps/mysite/bootstrap/autoload.php';

The second important entry is within the section Turn On The Lights. Make sure it says something like this (again can be a relative path as long as you get it right):

$app = require_once '/home/myuser/laravelapps/mysite/bootstrap/start.php';

Laravelapps' Public Path

One more thing to change is located at /home/myuser/laravelapps/mysite/bootstrap/paths.php within the section Public Path. Make sure it points back to yout web folder, such as:

'public' => '/home/myuser/webapps/mysite',

Other stuff

The settings above should do the trick. However, based on the (lack of) information you provided, it is impossible to rule out other issues with additional Laravel configuration files (located at /home/myuser/laravelapps/mysite/app/config or file permissions). Please, try the things above first and let us know how it goes?