The Slim Framework support forum has moved to This Tender forum is no longer maintained or monitored.

Serve all requests from a subdirectory

Dan Rogers's Avatar

Dan Rogers

02 Aug, 2012 06:25 PM

Say I have the following file structure:


Does slim provide a way to forward all requests to a subdirectory? In the above example.. say I wanted to detect a user agent in PHP and alias all root requests to one of the subdirectories, based on the user agent.

I realize this is not an ideal mobile workflow, but I am working on a project where it would help to serve the desktop dir using absolute urls for the assets, pointing to the root of the server.

  1. Support Staff 1 Posted by Josh Lockhart on 02 Aug, 2012 06:37 PM

    Josh Lockhart's Avatar

    I'm not an htaccess wizard, so I'll defer to others who may know htaccess rewrite magic more than I do. However, you may want to approach this from another direction. It seems that you want to separate logic for desktop users vs. mobile users.

    1. You can create two separate apps in either subdirectories. This would require the app URLs to include "/desktop" or "/mobile" prefixes, so that is likely undesirable.

    2. You can create one Slim app and serve either desktop templates or mobile templates based on user agent. This would require the controller logic to be the same for both desktop/mobile users (which is likely true), but you can easily serve different templates. This is my recommendation.


  2. 2 Posted by Dan Rogers on 02 Aug, 2012 06:47 PM

    Dan Rogers's Avatar

    Thanks Josh!

    In this particular case, the desktop site is already built- so I was hoping to get magical with the aliasing. However, I don't think this is something PHP is very good at.

    I will likely end up keeping the routing at the top level, and will prefix the assets accordingly (eg. /desktop/images/logo.png).

  3. Support Staff 3 Posted by Brian Nesbitt on 02 Aug, 2012 07:07 PM

    Brian Nesbitt's Avatar

    You could follow the same logic I proposed for a multilingual site:

    You can have the routes with or without a client defined (desktop, mobile, etc) and then in a slim.before hook you can modify the URI appropriately either injecting the client modifier or removing it and setting an internal client flag for that request.

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:


Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac