Laravel 漂亮的 URL 和路由在 LAMP 上不起作用

Ale*_*len 2 php apache .htaccess mod-rewrite

我使用 Laravel 创建了 Web 应用程序,我在 Laravel 服务器 ( php artisan serve)上对其进行了测试,现在我想将它放在 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>
Run Code Online (Sandbox Code Playgroud)

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

<VirtualHost *:80>
        ServerAdmin webmaster@localhost
        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>
Run Code Online (Sandbox Code Playgroud)

我用这个命令启用了 mod_rewrite: sudo a2enmod rewrite

我正在使用 Ubuntu 14.04。

更新:

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

小智 6

转到 /etc/apache2/apache2.conf 文件并确保它看起来像这样:

<Directory /var/www/html>
  Options Indexes FollowSymLinks
  Allowoverride All
  Require All Granted   
</Directory>
Run Code Online (Sandbox Code Playgroud)

您可以在之后立即找到它

<Directory /usr/share> 
.... 
</Directory>
Run Code Online (Sandbox Code Playgroud)

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