CharlesW's avatar

Routing to static page

Hello,

I'm a complete newbie to Lumen (and Laravel).

I have a static resources/views/docs folder that I just want displayed as-is. In my routes.php I do this:

$app->get('/docs', function() {
    return view('docs.index');
});

That works, in that it returns the index.php. Unfortunately, that page's request for its resources (in sub-folders css, fonts, etc.) fails, I assume because the router isn't explicitly handling routes other than /docs.

Another way to put it: I want /docs/* URLs to point to /resources/views/docs/* and can't figure out how to do that.

— Charles

0 likes
8 replies
CharlesW's avatar

@mstnorris Thanks, but unfortunately there are hundreds of files. I feel like there must be a more elegant answer than cataloguing them all and writing individual routes for them.

CharlesW's avatar

@mstnorris I'm building a REST API, and the \docs folder consists of auto-generated API documentation. My other idea was to simply plop it into /public, but I haven't figured out how to create a RewriteRule exception for that folder either.

mstnorris's avatar

I see, so you want the structure of the docs folder to be treated just like "old" websites where a URL maps directly to the structure of the directories?

1 like
bashy's avatar
bashy
Best Answer
Level 65

Why not reference them in the public folder?

Another option (without knowing what you're doing) is to exclude those files/folders from the rewrite. What web server software are you using? If you have a route with the same name as a folder, you will want to exclude the sub folder.

Edit: Apache?

RewriteCond $1 !^(docs)($|/)

// or 
RewriteRule ^(docs)($|/) - [L]
2 likes
CharlesW's avatar

@mstnorris Yes, exactly.

@bashy Thank you! I moved /docs back to /public, updated my .htaccess to look like this, and it appears to work great.

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

    # Passthrough for requests to /docs (CW 2015/6/16)
    RewriteRule ^(docs)($|/) - [L]

    # Redirect Trailing Slashes...
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]

</IfModule>

— Charles

2 likes

Please or to participate in this conversation.