简体   繁体   中英

dynamically create subdomain path for images

I'm looking for a PHP script that will rewrite my image paths to a subdomain. I currently have a script that performs this action, but it's difficult to use on my local development. Here is my current script:

<?php
$IMG_BASE_URL1="http://img.mysite.com/";
?>

...and then for the image...

<img src="<?php echo $IMG_BASE_URL1; ?>images/ui/logo.png">

This works great but it doesn't allow me to see the images locally while I'm developing the page. Is there a way to globally load the images from my subdomain without including <?php echo $IMG_BASE_URL1; ?> <?php echo $IMG_BASE_URL1; ?> in the src path?

If you're on Apache (?) you could setup a virtual host to simulate your subdomain.

Here's a nice article on it, I've done it a few days ago: http://apptools.com/phptools/virtualhost.php

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM