为什么Heroku修剪尾部斜杠? [英] Why is Heroku trimming trailing slashes?

查看:113
本文介绍了为什么Heroku修剪尾部斜杠?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Laravel webapp,正在为Heroku环境开发。在heroku环境中,如果我访问带有斜杠的网址(IE http://example.com/ ),我会得到一个301重定向删除结尾斜杠(IE http://example.com )。这将是很好的行为,除了重写从https移动到http!

我花了一些时间尝试在本地开发环境中重现问题,但我不能这样做,这导致我相信问题在于Heroku的Apache配置,但是上传一个自定义的.htaccess关闭RewriteEngine并没有停止重写。

有没有人遇到过类似的问题?



我的procfile只包含 web:vendor / bin / heroku-php-apache2 public ,所以它非常小。

解决方案

Heroku不会执行此类重定向。如果启用,Apache会为目录索引添加斜线,但就是这样。



您的应用程序正在执行重定向,无论是在代码中还是在 .htaccess ,并且请求协议不会被保留,因为对dyno的请求是HTTP - 在负载均衡器处终止SSL。



设置您的应用程序信任Heroku负载均衡器作为代理,以便从 X-Forwarded-Proto 读取请求协议,或者改变您的重写规则来做到这一点。


I have a Laravel webapp that I am developing for a Heroku environment. On the heroku environment, if I visit a url with a trailing slash (I.E. http://example.com/) I get a 301 redirect removing the trailing slash (I.E. http://example.com). This would be fine behavior, except that the rewrite is moving from https to http!

I've spent some time trying to reproduce the issue locally in my development environment and I cannot, which has led me to believe that the issue is with Heroku's configuration of Apache, but uploading a custom .htaccess turning RewriteEngine Off didn't stop the rewrite either.

Has anyone encountered a similar issue?

My procfile just containsweb: vendor/bin/heroku-php-apache2 public so it's quite minimal.

解决方案

Heroku does not perform such redirects. Apache adds slashes for directory indexes if enabled, but that's it.

Your application is doing that redirect somewhere, either in code or a .htaccess, and the request protocol is not preserved because the request to the dyno was HTTP - termination of SSL happens at the load balancer.

Set up your application to trust the Heroku load balancer as a proxy so it reads the request protocol from X-Forwarded-Proto, or change your rewrite rules to do just that.

这篇关于为什么Heroku修剪尾部斜杠?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆