Question

We have a register with all the files(WEB pages) that should be served from our WEB server. Can I configure Apache to execute specific script/program which will verify that requested page is registered? If the requested page is not registered "Page not found" will be presented.

Was it helpful?

Solution

I Did read your question a couple of times but im still not 100% understanding of what your asking. Please update with some more details.

Apache will send a 404 if a page is not found so im assuming you are allowing arbitrary files on your server (in-dev or versioned files ect) but are trying to find out how to check files or the request against a list of allowed files before the file is loaded.

This can be accomplished with PHP and mod_rewrite,

So with PHP and a crude example you could do something like:

<?php
$path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH); 

if(check_register($path)){
    //load page into buffer
    ob_start();
    require($path);

    echo ob_get_clean();
}else{
    exit(header($_SERVER['SERVER_PROTOCOL'].' 404 Not Found'));
}
?>

The check_register($path) function would be some mechanism to check whether the file is allowed and would return true or false, you would need to pass everything to this routing file (index.php) with mod_rewrite so as the request would not load the original file if it was there.

.htaccess

RewriteEngine On
Options -Indexes
RewriteBase /
RewriteCond %{REQUEST_URI} !^/index.php
RewriteRule .* index.php [L]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top