Szabolcs
Szabolcs

Reputation: 1533

How to restrict access to content on a website?

Lets say I have a domain: www.example.com, and I upload all the necessary files trough ftp. There are 10 pages on the site I want to be public, all the other content shouldn't be accessible to a visitor. As it is now, anyone could type in the following "www.example.com/data/text.txt", and get all the information in it.

So is there a way to restrict access to content on a site this way?

Upvotes: 0

Views: 93

Answers (1)

Raphael Müller
Raphael Müller

Reputation: 2200

If you know the version of the apache server:

create a .htaccess file in the folder you want to protect with the following content for apache version below 2.4 documentation:

Order deny,allow
Deny from all

and for apache versions >= 2.4 documentation

Require all denied

For custom error pages add the additional lines:

ErrorDocument 404     /404.html #for error 404 file not found
ErrorDocument 401     /404.html #for error 401 unauthorized
ErrorDocument 403     /404.html #for error 403 forbidden

If you want you can also use mod_rewrite as follows:

Add the following content to your .htaccess file in the root directory.

RewriteEngine On

RewriteBase /

RewriteRule ^yoursite1.html - [L]
RewriteRule ^yoursite2.html - [L]
RewriteRule ^error.html - [L]

#everything else
RewriteRule ^(.*)$ error.html [QSA,L]

Upvotes: 2

Related Questions