DEV Community


Overwriting base_href in SilverStripe 4

spekulatius1984 profile image Peter Thaleikis 🍪 Originally published at ・1 min read

There are use-cases which require to overwrite the URL the SilverStripe base-tag <% base_href %> defined in the theme. Usually this is the case if you are using a hosting environment which doesn't allow you to control the header parameters passed through by your web-server to the PHP run-time environment. For example this could be required if you are keen to enforce a SSL-only hosting setup behind a firewall or CDN.

There is a simple way to overwrite the base-href URL. The following configuration lives within a newly created file called "app/_config/baseurl.yml":

Name: baseurl
  environment: 'live'
  alternate_base_url: ""
Enter fullscreen mode Exit fullscreen mode

This will ensure your base href URL is set to the defined URL, here "".

Keep in mind, you will need to set the SS_ENVIRONMENT_TYPE in your local .env-file to dev to ensure this doesn't apply on your local development environment:

Enter fullscreen mode Exit fullscreen mode

Discussion (0)

Editor guide