-2

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.

user2038893
  • 336
  • 4
  • 6
  • what do you mean by a 'register'? Why would their be files on your server that you don't want served? – Pitchinnate Jun 27 '13 at 15:10
  • 1
    It concerns me to think that you are ok with allowing unregistered or unapproved files to get on your server in the first instance and that this is not a worry for you. – Anigel Jun 27 '13 at 15:17
  • The register is a database with file name and location, version, check sum and few other details about the file. The detail I silted are used to validate the file. – user2038893 Jun 28 '13 at 06:33
  • It is not a matter of week control. It is more for prevention of using obsolete versions. I might help against some hacking I guess too. – user2038893 Jun 28 '13 at 06:37

1 Answers1

0

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]
Lawrence Cherone
  • 46,049
  • 7
  • 62
  • 106