The Slim Framework support forum has moved to http://discourse.slimframework.com. This Tender forum is no longer maintained or monitored.

How to redirect directory in slim framework

NB's Avatar

NB

01 Dec, 2015 11:39 AM

I am trying to redirect a directory as I have multiple files in the directory and it is not possible to route every file separately. Without routing file is showing 404 error. Help!

  1. 1 Posted by troy on 01 Dec, 2015 01:40 PM

    troy's Avatar

    IF I understand your issue correctly, this seems easy to solve, and the solution has nothing to do with Slim. Can you use a symbolic link?

    On Unix-like platforms:

    ln -s /var/www/app/foo /var/www/app/public/bar
    
    Now everything in that "foo" directory will also be found in the new "bar" path. Your application (Slim or otherwise) will not know that "bar" is not a real directory. It just works. magic

    I did not read it, but this page seems to explain how to do the same thing in Windows:
    http://www.howtogeek.com/howto/16226/complete-guide-to-symbolic-lin...

  2. 2 Posted by troy on 01 Dec, 2015 03:42 PM

    troy's Avatar

    Thinking more about your question...a bunch of files that you want routes to...makes me think that these may be files you simply want to serve directly rather than have handled by Slim? If this is the case, know that you get to pick and choose which directories and which files are handled by Slim. You do this in your web server configuration--not in Slim.

    Here is one of my real Apache VirtualHosts except I changed the directory name to be generic:

    <VirtualHost _default_:80>
        ServerName www.mydomain.com
        DocumentRoot /var/www/myapp/public
        <Directory "/var/www/myapp/public">
            AllowOverride All
            Options All
            Require all granted
            RewriteEngine On
            RewriteCond %{REQUEST_FILENAME} !-f
            RewriteRule ^ index.php [QSA,L]
        </Directory>
    </VirtualHost>
    

    See those "Rewrite*" lines? Those tell my web server that if the file is found at the requested path, then serve it directly. If not found, then pass the requested path to my Slim handler (root index.php in the example above, but you could name this file anything you want). Once handed off to Slim, you'll need a specific Slim route that is ready to accept the requested path or you'll get the Slim-generated 404.

  3. Josh Lockhart closed this discussion on 12 Feb, 2021 07:41 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? 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