Laravel 和 Apache2:无法正确使用重定向
Laravel and Apache2 : unable to correctly use redirects
我对 Laravel 有疑问。在使用 Debian 8.5 运行的名为 fmbsrv130 的内联网 Apache 2.4.10 Web 服务器上,我想安装一个名为 sentinelle 的 Laravel 项目。
所以 Laravel 安装没问题,我可以用 http://fmbsrv130/sentinelle/ (I have the welcome page of Laravel). But if I try to go to http://fmbsrv130/sentinelle/1 (that does not exists), I have 404 from Apache2 that says "The requested URL /home/webadmin/sentinelle/public/index.php was not found on this server." If I try to access http://fmbsrv130/sentinelle/index.php/1 访问它 我有 Laravel 的 404:“抱歉,找不到您要查找的页面.
RouteCollection.php 第 161 行中的 1/1 NotFoundHttpException:..."
rewrite_mod 在 Apache 中正确启用。
这是 Apache 的配置文件(可用站点中的 000-default.conf):
Alias "/sentinelle" "/home/webadmin/sentinelle/public/"
<Directory "/home/webadmin/sentinelle/public/">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
为了测试,如果我尝试使用
修改 Laravel 的 public 文件夹中的 .htaccess 文件
RewriteEngine On
RewriteRule ^.*$ htaccess_tester.php
(htaccess_tester.php 是一个用于测试 .htaccessfile 内容的文件(在 GitHub 上查看它)并且当前位于 public 文件夹中),我有 Apache2 404 错误留言The requested URL /home/webadmin/sentinelle/public/htaccess_tester.php was not found on this server.
这是 .htaccess 文件的问题还是 Apache2 配置的问题还是 Laravel 配置的问题还是文件访问权限?
您的 mod_rewrite 是否已在您的 apache2 上启用,请确认它应该被启用以便 .htaccess 工作并在您的 .htaccess 文件中添加默认 laravel .htaccess 内容
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ / [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
如果这不起作用,请尝试从 public 目录中删除您的 index.php 并将其放置在 /sentinell
的根目录中,并将 .htaccess 修改为 RewriteRule ^ public/index.php [L]
应该可以解决问题
好的,最后我通过做一些修改找到了解决方案:第一个是将 .htaccess 文件放入 public 文件夹:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteBase /sentinelle/
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ / [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
(添加 RewriteBase /sentinelle/)
第二个是 default.conf Apache 文件:
Alias /sentinelle /home/webadmin/sentinelle/public/
<Directory "/home/webadmin/sentinelle/public">
AllowOverride All
Order allow,deny
allow from all
Require all granted
</Directory>
它解决了本主题中描述的问题,我将打开另一个,因为现在我对地址中的最后一个“/”有疑问 :)
我对 Laravel 有疑问。在使用 Debian 8.5 运行的名为 fmbsrv130 的内联网 Apache 2.4.10 Web 服务器上,我想安装一个名为 sentinelle 的 Laravel 项目。
所以 Laravel 安装没问题,我可以用 http://fmbsrv130/sentinelle/ (I have the welcome page of Laravel). But if I try to go to http://fmbsrv130/sentinelle/1 (that does not exists), I have 404 from Apache2 that says "The requested URL /home/webadmin/sentinelle/public/index.php was not found on this server." If I try to access http://fmbsrv130/sentinelle/index.php/1 访问它 我有 Laravel 的 404:“抱歉,找不到您要查找的页面. RouteCollection.php 第 161 行中的 1/1 NotFoundHttpException:..."
rewrite_mod 在 Apache 中正确启用。
这是 Apache 的配置文件(可用站点中的 000-default.conf):
Alias "/sentinelle" "/home/webadmin/sentinelle/public/"
<Directory "/home/webadmin/sentinelle/public/">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
为了测试,如果我尝试使用
修改 Laravel 的 public 文件夹中的 .htaccess 文件RewriteEngine On
RewriteRule ^.*$ htaccess_tester.php
(htaccess_tester.php 是一个用于测试 .htaccessfile 内容的文件(在 GitHub 上查看它)并且当前位于 public 文件夹中),我有 Apache2 404 错误留言The requested URL /home/webadmin/sentinelle/public/htaccess_tester.php was not found on this server.
这是 .htaccess 文件的问题还是 Apache2 配置的问题还是 Laravel 配置的问题还是文件访问权限?
您的 mod_rewrite 是否已在您的 apache2 上启用,请确认它应该被启用以便 .htaccess 工作并在您的 .htaccess 文件中添加默认 laravel .htaccess 内容
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ / [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
如果这不起作用,请尝试从 public 目录中删除您的 index.php 并将其放置在 /sentinell
的根目录中,并将 .htaccess 修改为 RewriteRule ^ public/index.php [L]
应该可以解决问题
好的,最后我通过做一些修改找到了解决方案:第一个是将 .htaccess 文件放入 public 文件夹:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteBase /sentinelle/
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ / [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
(添加 RewriteBase /sentinelle/)
第二个是 default.conf Apache 文件:
Alias /sentinelle /home/webadmin/sentinelle/public/
<Directory "/home/webadmin/sentinelle/public">
AllowOverride All
Order allow,deny
allow from all
Require all granted
</Directory>
它解决了本主题中描述的问题,我将打开另一个,因为现在我对地址中的最后一个“/”有疑问 :)