In my PHP code I’ve got references to a URL on another website. I’m testing my website locally (using XAMPP). Is it possible to get Apache to automatically replace the domain of this other website for localhost?
For example my PHP code might be:
<?php echo "<a href='http://www.othersite.com'>Click me</a>"; ?>
And I’d like for my local Apache to alias this to
<?php echo "<a href='http://localhost'>Click me</a>"; ?>
Is this possible?
[edit] Just to clarify, I want to do this without changing PHP code. Might not be possible, but thought it worth asking as it would make testing locally simpler without having to have hacks in the PHP code.
Cheers,
Dan.
Apache supports aliases for virtual hosts. Use the
ServerAliasdirective and just create an alias for the other domain.You’ll have to update your hosts file (what OS are you using?) to point the other domain to localhost (so it doesn’t do a regular old DNS lookup). Restart Apache and you should be in business.