My site is almost up and running, but in the original code there are, for example img src="/design/pic1.png" and so one. On the real server, there is a must dir, web, so the new paths should be img src="web/design/pic1.png" but I don’t want to rewrite all paths.
Is there another option?
My site is almost up and running, but in the original code there are,
Share
Depending on your set up, one approach would be to have a constant that dictates your base path which is dependant on your environment.
For example, suppose in your development environment you’re happy to put all images in
$WEB_ROOT . "/design/", but on your production environment it’s$WEB_ROOT . "/web/design/", then you might end up with something like this:Then, in your HTML, you could use this
BASE_PATHconstant like so:How you decide what is
ENV_DEVandENV_PRODin this example, is entirely up to you.One approach would be to detect it based on the domain (using
$_SERVER['HTTP_HOST'], which has some caveats).Another approach would be to initialise this in your web configuration. Suppose you’re using Apache2, you might use the
SetEnvdirective.In your
httpd.conf:Which you can access in PHP using: