D
D
Danil Chekalin2014-06-16 20:39:24
PHP
Danil Chekalin, 2014-06-16 20:39:24

How to force php build-in server to return non-existent static?

I use a built-in server. I want requests for non-existent statics (cms / init.js in my case and others) to be sent to index.php, to process the request directly by php itself to generate init.js
Current config:

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

    RewriteEngine On

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

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

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Danil Chekalin, 2014-06-17
@dakiesse

Figured it out, it turns out the build-in server doesn't support .htaccess. Routing must be implemented using php.

<?php
# routing.php
if (preg_match('/\.(?:png|jpg|jpeg|gif)$/', $_SERVER["REQUEST_URI"])) {
    return false;
} else {
    include __DIR__ . '/index.php';
}

Next, we launch the server itself with a custom PS entry point
. This example will still not give the generated js, but here you can already add

M
mumrum, 2014-06-17
@mumrum

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
remove

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question