{"id":18,"date":"2014-08-03T15:04:00","date_gmt":"2014-08-03T19:04:00","guid":{"rendered":"https:\/\/kimsal.com\/blog\/?p=18"},"modified":"2014-08-03T15:04:00","modified_gmt":"2014-08-03T19:04:00","slug":"is-your-code-portable-to-subfolders","status":"publish","type":"post","link":"https:\/\/kimsal.com\/blog\/2014\/08\/03\/is-your-code-portable-to-subfolders\/","title":{"rendered":"Is your code portable to subfolders?"},"content":{"rendered":"\n<p>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.<\/p>\n\n\n\n<p>In both cases, and in other projects I\u2019ve seen, there\u2019s 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\u2019s the answer? \u201cJust make a new vhost!\u201d typically. Quite a pain, and seems to be a real shortcoming of all(?) major frameworks I\u2019ve 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.<\/p>\n\n\n\n<p>I\u2019ve gotten more used to Java web stuff (or, at least Spring) which respects whatever pathing your app is deployed to.<\/p>\n\n\n\n<p><code>redirect(uri:\"\/foo\")<\/code><\/p>\n\n\n\n<p>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<\/p>\n\n\n\n<p>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<\/p>\n\n\n\n<p><code>$app->get('\/sample-url-path(\/)', function() use ($app) {<\/code><br>and<br><code>$app->redirect(\"\/\");<\/code><\/p>\n\n\n\n<p>and there\u2019s no way to just have the code work normally under something like \u201chttp:\/\/localhost\/slimdev\/\u201d. 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\u2019t require me to rewrite dozens of lines of code?<\/p>\n\n\n\n<p>Are there any PHP frameworks that can work relatively from a non-root-domain URL invocation?<\/p>\n\n\n\n<p>Perhaps I just need to roll with things, but it makes working with anyone else\u2019s code (even based on a framework) that much harder.<\/p>\n\n\n\n<p>Maybe try grabbing your own code sometime and reinstalling it in a \u2018non-traditional\u2019 way, and see how many assumptions you\u2019ve baked in are really necessary, vs just using defaults.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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\u2019ve seen, there\u2019s a huge assumption that the code will be run from the root of&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"_kad_post_classname":"","footnotes":""},"categories":[1],"tags":[],"class_list":["post-18","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/kimsal.com\/blog\/wp-json\/wp\/v2\/posts\/18","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kimsal.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kimsal.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kimsal.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kimsal.com\/blog\/wp-json\/wp\/v2\/comments?post=18"}],"version-history":[{"count":0,"href":"https:\/\/kimsal.com\/blog\/wp-json\/wp\/v2\/posts\/18\/revisions"}],"wp:attachment":[{"href":"https:\/\/kimsal.com\/blog\/wp-json\/wp\/v2\/media?parent=18"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kimsal.com\/blog\/wp-json\/wp\/v2\/categories?post=18"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kimsal.com\/blog\/wp-json\/wp\/v2\/tags?post=18"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}