Laravel 5 returns 404 error for every page

拟墨画扇 提交于 2020-01-15 07:35:10

问题


I am having trouble configuring Apache and my project's .htaccess file. I am storing it in a subfolder in /var/www/html, and aliasing it via Apache. I have also added RewriteBase to my .htaccess file. Accessing to the alias (server.ip/blog) lists the public directory, but everything I try to access returns a 404 error. Any ideas?

.htaccess:

Options +FollowSymLinks
RewriteEngine On

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

Apache site .conf:

Alias /blog/ "/var/www/html/exoblog/public" 

<Directory "/var/www/html/exoblog/public/">
    Options Indexes FollowSymLinks MultiViews
    AllowOverride all
        Order allow,deny
    Allow from all
</Directory>

VirtualHost:

<VirtualHost *:80>
    ServerAdmin mymail@gmail.com
    DocumentRoot "/var/www/html/exoblog/public"
    ServerName eneko.dev
    ServerAlias www.eneko.dev
    ErrorLog "/var/log/apache2/exob.log"
    CustomLog "/var/log/apache2/exob.log" common

<Directory "/var/www/html/exoblog/public">
Options Indexes MultiViews FollowSymLinks
                AllowOverride All
                Order allow,deny
                Allow from all
        </Directory>

</VirtualHost>

Thanks in advance!


回答1:


Firstly, remove the slash from /index.php, and move your RewriteBase up:

Your .htaccess file should be saved in your blog directory and should contain the following:

RewriteEngine on
RewriteBase /blog/

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

Options +FollowSymlinks does not need to be in that file as the configuration already has it set up.

If you are using Apache 2.4 (as opposed to 2.2), your virtual host <directory...> should look like this:

<Directory "/var/www/html/exoblog/public">
    Require all granted
    AllowOverride All
    Options Indexes Multiviews FollowSymLinks
</Directory>

Also, this does not need to be duplicated in the conf file.



来源:https://stackoverflow.com/questions/30074388/laravel-5-returns-404-error-for-every-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!