I would never hard code a value that changes per environment. As @PJC said, this isn't a consistently easy thing to do in Apex. I would suggest looking into Custom Settings. From the documentation:
Custom settings are similar to custom objects and enable application
developers to create custom sets of data, as well as create and
associate custom data for an organization, profile, or specific user.
All custom settings data is exposed in the application cache, which
enables efficient access without the cost of repeated queries to the
database. This data can then be used by formula fields, validation
rules, Apex, and the SOAP API.
So, you can create a Custom Setting, let's call it Force_com_Site_Url__c and it has a URL field called Site_Url__c. To access that, it would be
Force_com_Site_Url__c siteSettings = Force_com_Site_Url__c.getInstance();
System.debug('This is the URL - ' + siteSettings.Site_Url__c);
This doesn't count against any database limits and all of this information is cached so it returns very quickly. It is meant to act like a property file in other programming environments.