I want to generate URL with https:// as a prefix, using the Twig function url(). However, the generated URL is always http://.
I made the setup given here: https://symfony.com/doc/6.2/routing.html#forcing-https-on-generated-urls.
My config/packages/framework.yaml:
framework:
http_method_override: false
handle_all_throwables: true
...
My config/routes.yaml:
controllers:
resource:
path: ../src/Controller/
namespace: App\Controller
type: attribute
defaults: [https] // note HTTPS here
I am using the PROD environment.
My .env file is:
APP_ENV=prod
APP_URL=https://something... // note HTTPS here
Cache has been cleared with prod option.
However, when I use from my twig template:
{{ url('my_route') }}
the generated route is correct but still in http (and not https).
Am I missing something ?
Looking here: https://symfony.com/doc/current/routing.html#forcing-https-on-generated-urls you will see you missed the schemes key in your config. Here is the example given:
# config/routes/annotations.yaml
controllers:
resource: '../../src/Controller/'
type: annotation
defaults:
schemes: [https]
Or do the following on a per route basis:
#[Route('/login', name: 'login', schemes: ['https'])]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With