How Craft Determines the Site URL
This page covers legacy techniques that only apply to Craft 2.
In Craft 3 and 4, the base URL for each site is typically defined by the @web
alias in combination with a subpath and/or environment variables. Read about modern configuration and site settings.
When Craft is determining the Site URL (such as to set the value of the siteUrl
global variable), it will check the following locations, in this order:
1. The siteUrl config setting
If this is set to a string, that value will be used. If it’s an array, Craft will check if the array contains a value for the current locale, and use that if so. Otherwise the first value in the array will be used. This is the recommended way to set your Site URL.
2. The CRAFT_SITE_URL
PHP constant
If this is defined, Craft will parse it for environment variables and use the result.
3. The Site URL setting in the Control Panel’s general settings
This is the URL that you chose when installing Craft, and can be edited from Settings → General.