Project

General

Profile

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

Added by shashank 28 days 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 28 days 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 27 days 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 27 days 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)