drsw9390405 2016-02-08 21:48
浏览 31
已采纳

为什么Heroku修剪拖尾斜线?

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.

  • 写回答

1条回答 默认 最新

  • dragon2025 2016-02-14 09:51
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?