Is your code portable to subfolders?

Have been dealing with a couple of PHP projects recently which have been a far bigger pain in the backside than I anticipated, and both had some of the same stumbling blocks.

In both cases, and in other projects I’ve seen, there’s a huge assumption that the code will be run from the root of a domain, and all url and routing management have this assumption baked in to everything they touch. What’s the answer? “Just make a new vhost!” typically. Quite a pain, and seems to be a real shortcoming of all(?) major frameworks I’ve looked at of late. I remember being a bit surprised at Zend Framework as far back as 2006(!) having this be the recommended way of building with the framework.

I’ve gotten more used to Java web stuff (or, at least Spring) which respects whatever pathing your app is deployed to.

redirect(uri:"/foo")

will redirect to bar.com/ if the code is deployed to bar.com, but it will redirect to bar.com/subbar/ if the code is deployed to bar.com/subbar

I recently hit this snag in a PHP project I picked up which uses Slim framework. There are dozens and dozens of URL and route references in multiple files, like

$app->get('/sample-url-path(/)', function() use ($app) {
and
$app->redirect("/");

and there’s no way to just have the code work normally under something like “http://localhost/slimdev/”. I *have* to create a new hostname and vhost just to get this to run. Am I missing a simple global config option someplace that wouldn’t require me to rewrite dozens of lines of code?

Are there any PHP frameworks that can work relatively from a non-root-domain URL invocation?

Perhaps I just need to roll with things, but it makes working with anyone else’s code (even based on a framework) that much harder.

Maybe try grabbing your own code sometime and reinstalling it in a ‘non-traditional’ way, and see how many assumptions you’ve baked in are really necessary, vs just using defaults.

Similar Posts

  • Laravel down migrations

    I get an email newsletter from Martin Joo every week or so. The newsletters generally have some useful tips around the Laravel framework or sometimes just general development tips. I’ve learned a couple of neat tricks here and there, and will continue to receive. This morning I received an email with a Laravel ‘tip’ regarding…

  • chunked file uploads with plupload

    Holy tamole… Have been wrestling with a client project using ‘plupload’ with a user base consistently uploading files from 150-500meg on a daily basis. They’d been uploading to youtube/vimeo mostly, because the experience with the older uploader (still plupload earlier version) was bad – slow, mostly, but some issues about determining whether items were uploaded/processed…

  • CyclopsMonitor

    I’ve been posting more about this new service over on linkedin, but haven’t posted much here. CyclopsMonitor is a web monitoring service – checking if a web address is up, how fast it responds, if specific content is available, when SSL/TLS certs expire, when domain name expires, and… sending you notifications when problems occur. Currently,…

  • Onboarding freelancers

    Maari Casey over at uncompany had a recent LinkedIn post about planning for freelancers. She made some good points, but I think skipped one, and it’s not just relevant for freelancers. Even well before an organization might need extra work – be it freelance or employee – companies need to have a plan for onboarding….

  • Open Source TechFinder

    Inspired by the AUTM conference, I got inspired to look at some of the common processes techtransfer folks do. Main idea was to try to develop something relatively ‘standalone’ that might address a use case I learned about, so I decided on building a web-based open source techfinder tool to publish licensable technologies. The notion…

Leave a Reply

Your email address will not be published. Required fields are marked *