[英]Laravel route not found with https
我在routes.php的任何路由之上定义了一条简单的路由:
Route::get('/test', function () {
echo 'hello';
});
通过http访问时,它可以工作,但它提供:
The requested URL /test was not found on this server.
当我尝试通过https访问时。
我在互联网上进行了大量搜索,但找不到任何解决方案。
我的主页同时加载了http和https,但其他路由却无法正常工作。 我需要一些额外的配置吗?
编辑:
的.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 ^(.*)/$ /$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>
请指导我。
感谢名单。
更新APP_URL
在.env
文件,以便它开头https://
,而不是http://
:
APP_URL=https://yourserver.com
将此添加到您的SSL Apache配置(在Ubuntu上: default-ssl.conf
):
<Directory /var/www/public/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
allow from all
</Directory>
我也遇到了同样的问题,我只需修改.htaccess文件即可解决此问题。 通常,这是我们的重写模块存在的问题。 尝试此希望它对您有用。
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
还要确保文件夹结构在本地和生产服务器上匹配。
如果有人对Laravel中的无限循环有问题,可以采取以下解决方案:
RewriteEngine On
# If we receive a forwarded http request from a proxy...
RewriteCond %{HTTP:X-Forwarded-Proto} =http [OR]
# ...or just a plain old http request directly from the client
RewriteCond %{HTTP:X-Forwarded-Proto} =""
RewriteCond %{HTTPS} !=on
# Redirect to https version
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.