Project

General

Profile

[Solved] Blocking the access with specific extension file through browser

Added by shashank about 1 month ago

Webserver home directory is cgi-bin

We have two files which is home.html, header.hf.

Url: https://<ip>/cgi-bin/home.html
Url: https://<ip>/cgi-bin/header.hf

if user request any (*.hf) file we need to restrict in browser by sending to notfound page using rewrite.

Tried like below but below regular expression is not working.

$HTTP["url"] == "/cgi-bin/*.hf" {
url.rewrite = ( "" => "/cgi-bin/notfound.ha" )
}

Which regular expression we should use to restrict all .hf files at a time??


Replies (3)

RE: Blocking the access with specific extension file through browser - Added by gstrauss about 1 month ago

== is an exact match condition, which will not match your shell file glob.
=~ is for a regex condition, but what you wrote above is not a proper regex. You used a shell file glob instead of a regex.

$HTTP["url"] =~ "^/cgi-bin/.*\.hf$" {
    url.rewrite = ( "" => "/cgi-bin/notfound.ha" )
}

or more simply use the regex match in url.rewrite
url.rewrite = ( "^/cgi-bin/[^?]*\.hf" => "/cgi-bin/notfound.ha" )
or deny serving all *.hf as a static file using
static-file.exclude-extensions += (".hf")

RE: [Solved] Blocking the access with specific extension file through browser - Added by shashank about 1 month ago

Tried the changes but still it is not working. After making the changes every file it is rewriting to notfound.ha.

RE: [Solved] Blocking the access with specific extension file through browser - Added by gstrauss about 1 month ago

Please read the following very carefully: How to get support

Then, read mod_rewrite and try testing some alternatives on your own.

    (1-3/3)