2014-11-21 111 views
1

我创建了Laravel的Web应用程序,这是我laravel服务器(php artisan serve)上测试过,现在我希望把它放在LAMP这样我就可以进一步测试,但什么是错的。Laravel漂亮的URL和路由不工作的LAMP

当我访问localhost/public/我得到我的主页,但当我点击我的应用程序内的任何链接时,我得到Not found错误。另一方面,当我手动输入localhost/public/index.php/someURL然后我得到链接页面。

有人能告诉我如何解决这一问题?

这是我.htaccess文件中public目录:

<IfModule mod_rewrite.c> 
    <IfModule mod_negotiation.c> 
     Options -MultiViews 
    </IfModule> 

    RewriteEngine On 

    RewriteBase/
    RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC] 
    RewriteRule ^(.*)$ http://%1/$1 [R=301,L] 

    # Redirect Trailing Slashes... 
    RewriteRule ^(.*)/$ /$1 [L,R=301] 

    # Handle Front Controller... 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteRule^index.php [L] 
</IfModule> 

<IfModule mod_deflate.c> 
<FilesMatch "\.(html|php|txt|xml|js|css)$"> 
SetOutputFilter DEFLATE 
</FilesMatch> 
</IfModule> 

这是的Apache2的conf文件的内容(/etc/apache2/sites-available/000-default.conf):

<VirtualHost *:80> 
     ServerAdmin [email protected] 
     DocumentRoot /var/www/html/ 

     <Directory "/var/www/html"> 
       AllowOverride All 
     </Directory> 

     ErrorLog ${APACHE_LOG_DIR}/error.log 
     CustomLog ${APACHE_LOG_DIR}/access.log combined 
</VirtualHost> 

我启用了此命令的mod_rewrite:sudo a2enmod rewrite

我使用的是Ubuntu 14.04。

UPDATE:

应用放在里面/var/www/html/

+0

的是,原来的htaccess与Laravel或一些家庭BREW版本捆绑?如果是后者,请考虑尝试使用默认值。 – 2014-11-21 16:59:49

+0

@AndréDaniel默认htaccess只修复了部分问题。现在命名路线的作品,但如果我手动创建链接'/约',那么我再次找不到错误。 – Alen 2014-11-21 17:03:26

回答

1

这是我固定它。我创造了另一个.htaccess文件并把它放在根目录/ www/html等/:从这里取

<IfModule mod_rewrite.c> 
    RewriteEngine on 
    RewriteCond %{REQUEST_URI} !^public 
    RewriteRule ^(.*)$ public/$1 [L] 
</IfModule> 

信息:http://driesvints.com/blog/laravel-4-on-a-shared-host

4

转到/etc/apache2/apache2.conf中的文件,并确保它看起来是这样的:

<Directory /var/www/html> 
    Options Indexes FollowSymLinks 
    Allowoverride All 
    Require All Granted 
</Directory> 

你可以找到它的权利之后

<Directory /usr/share> 
.... 
</Directory> 

执行mod_rewrite并重新启动apache并它应该工作!

+0

对不起,但它不工作。我设法通过设置的DocumentRoot在/ var/www/html等/公众“修复”,但这个不是我想要的,因为我想给这个应用程序的客户端和客户端没有开发人员,所以他/她不知道如何设置Apache配置 – Alen 2014-11-21 21:32:14