So here's a situation many web developers find themselves in, a client comes along with a website that's perhaps 10 years old, full of absolute links for whatever reason - and you are tasked with doing some development work on it.
Naturally you need to get this site onto your development server/workstation under a different doman name so you can work on and test it, but there are hundreds, maybe thousands of files, maybe different technologies too, some PHP, some cgi, some perl, some plain old HTML, so changing the domain in the absolute links spread around the place just isn't practical, especially as when you're done it's all going back to the live domain name anyway, what a waste of effort changing links would be.
Well, cry not intrepid web developer for if you are using Apache 2 on your dev system, then Content Filtering comes to the rescue! There are a number of "Output Filters" which Apache can feed ALL your content delivered to the user through, right before it gets out of the server, so it doesn't matter where the content came from, php, cgi, plain old html a Content Filter can rewrite the content.
The module I choose to use is "mod_line_edit", which is basically regular expression replacements, the reason I chose this above say, mod_sed (Unixites will know what sed is, mod_sed is an output filter embedding sed) is simple - Ubuntu has mod_line_edit (sudo apt-get install libapache2-mod-line-edit && sudo /etc/init.d/apache2 restart)
Here's an example configuration:
SetEnv LineEdit "text/plain;text/css;text/html"
LERewriteRule https?://(www\.)?example\.com http://example-development.yoursite.co.nz Ri
Throw something like that into your or somewhere and you instantly fixed all those problem URLS on your development system, without touching the source files at all.
Hooray! Since you saved some time reward your developy prowess with watching some Garfunkle and Oates
PS: in the above, the flags to LERewriteRule mean (R)egular Expression and (i)nsensitive as you may expect, while the ANY in the directive above mean that any of the usual line ending formats will be recognised in content.
Other related posts:
Xero vs. Quickbooks, from a Quickbooks User
Vodafone Website Failure Fails
CSS namespacing, somebody tell me what I'm doing wrong.
Add a comment
Please note: comments that are inappropriate or promotional in nature will be deleted.
E-mail addresses are not displayed, but you must enter a valid e-mail address to confirm your comments.
Are you a registered Geekzone user? Login to have the fields below automatically filled in for you and to enable links in comments. If you have (or qualify to have) a Geekzone Blog then your comment will be automatically confirmed and placed in the moderation queue for the blog owner's approval.