DEV Community

Peter Thaleikis 🍪
Peter Thaleikis 🍪

Posted on • Originally published at bringyourownideas.com

1

Overwriting base_href in SilverStripe 4

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
Only:
  environment: 'live'
--------
SilverStripe\Control\Director:
  alternate_base_url: "https://bringyourownideas.com"
Enter fullscreen mode Exit fullscreen mode

This will ensure your base href URL is set to the defined URL, here "https://bringyourownideas.com".

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:

SS_ENVIRONMENT_TYPE="dev"
Enter fullscreen mode Exit fullscreen mode

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs