I have a Weblication which provides access to certain pages only to some users. Now there are some files linked on these pages. If someone has the URL everyone can access these files (in this case the search engines). This should be changed! How can I protect such a directory? I thought about two possibilites:
- htaccess: Enter username + password every time a new user is created -> not suitable for that type of project (would also need a second login)
- download.php?file=xxx: Don’t know how to include such one on all Links in Weblication (static pages)
Are there any other possibilities?
Taken and translated from this link (but is only available in the WaybackMachine).
Personalised output with the help of mod_rewrite
With the help of the function
wCheckPermissionViewFilephp files can be personalized. It is sufficient to perform the permission check in the header of a file to suppress the output. If other file types should be personalised (e.g. ZIP, PDF, …),wPermission.cgior a custom php file can be used.To save the editor some work for writing
wPermission.cgibefore every personalised link to a binary file, instead the Apache modulemod_rewritecan be used. With this it is possible to convert every accessed link before execution. For example you could define thatwPermission.cgiis in front of each webserver call. The direct execution could also be redirected with the help of a php file (nowPermission.cginecessary).Example of a
.htaccessfile via check from Perl (wPermission.cgi)Example of a
.htaccesfile via check from PHP (e.g. download.php, see below)Explanation
If you would like to personalise all PDF and ZIP files within the directory
/de/dokumentewithout changing the links, you could put a.htaccessfile into that directory. In this file the redirect rules are defined.The rules can be extended with arbitrary file extensions,
NCstands for non case sensitive. Be aware that the rules are also inherited onto sub directories.The binary files itself have to be checked in and provided with the according personalisation.
If you would like to check if the file is in a valid publishing time period (e.g. online or offline), then do the check before the permission check via PHP API
wIsOnline.Example: download.php for the implementation “
.htaccesfile via check from PHP (e.g. download.php)”For newer versions of
Weblicationthis link could help. It is in German, because the manufacturers main language is German.