Laravel和Apache2:无法正确使用重定向

编程入门 行业动态 更新时间:2024-10-06 04:12:40
本文介绍了Laravel和Apache2:无法正确使用重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我对Laravel有问题.在要运行Debian 8.5的名为fmbsrv130的Apache 2.4.10 Web服务器上,我想安装一个名为sentinelle的Laravel项目.

I have an issue with Laravel. On an intranet Apache 2.4.10 Webserver runing with Debian 8.5, named fmbsrv130, I would like to install a Laravel Project named sentinelle.

Laravel安装正常,我可以使用 fmbsrv130/sentinelle/(我有Laravel的欢迎页面).但是,如果我尝试转到 fmbsrv130/sentinelle/1 (不存在),在Apache2中有404,显示在此服务器上找不到所请求的URL/home/webadmin/sentinelle/public/index.php".如果我尝试访问 fmbsrv130/sentinelle/index.php/1 Laravel的404:很抱歉,找不到您要查找的页面.RouteCollection.php第161行中的1/1 NotFoundHttpException:..."

So Laravel installation is OK, I can access to it with fmbsrv130/sentinelle/ (I have the welcome page of Laravel). But if I try to go to 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 fmbsrv130/sentinelle/index.php/1 I have the 404 from Laravel : "Sorry, the page you are looking for could not be found. 1/1 NotFoundHttpException in RouteCollection.php line 161: ..."

rewrite_mod已在Apache中正确启用.

rewrite_mod is correctly enabled in Apache.

这是Apache的配置文件(站点可用的000-default.conf):

Here is config file of Apache (000-default.conf in sites-available) :

Alias "/sentinelle" "/home/webadmin/sentinelle/public/" <Directory "/home/webadmin/sentinelle/public/"> Options Indexes FollowSymLinks AllowOverride All Require all granted </Directory>

为了进行测试,如果我尝试使用

For testing, if I try to modify .htaccess file from public folder of Laravel with

RewriteEngine On RewriteRule ^.*$ htaccess_tester.php

(htaccess_tester.php是用于测试.htaccessfile内容的文件(在GitHub上查看),当前位于公共文件夹中),我有Apache2 404错误消息所请求的URL/home/webadmin/在此服务器上未找到sentinelle/public/htaccess_tester.php.

(htaccess_tester.php is a file that is used to test content of .htaccessfile (see it on GitHub) and is currently into public folder), I have Apache2 404 error message The requested URL /home/webadmin/sentinelle/public/htaccess_tester.php was not found on this server.

是.htaccess文件问题还是Apache2配置问题还是Laravel配置问题或文件访问权限?

Is it an issue from .htaccess file OR an issue from Apache2 config OR an issue from Laravel config OR a file access right ?

推荐答案

好,最后我通过做一些修改找到了一个解决方案:第一个是将.htaccess文件放入公用文件夹:

OK so finally I found a solution by doing some modifications : first one is .htaccess file into public folder:

<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 ^(.*)/$ /$1 [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/)

(Adding RewriteBase /sentinelle/)

第二个是进入default.conf Apache文件:

And the second one was into default.conf Apache file :

Alias /sentinelle /home/webadmin/sentinelle/public/ <Directory "/home/webadmin/sentinelle/public"> AllowOverride All Order allow,deny allow from all Require all granted </Directory>

它解决了本主题中描述的问题,我将打开另一个,因为现在我的地址中有最后一个"/" :)

It solved the issue described into this topic, I'll open another one because now I have issue with last "/" in address :)

更多推荐

Laravel和Apache2:无法正确使用重定向

本文发布于:2023-11-02 06:54:05,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1551674.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:重定向   正确   Laravel

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!