How To Close Access To Pages

Table of contents:

How To Close Access To Pages
How To Close Access To Pages

Video: How To Close Access To Pages

Video: How To Close Access To Pages
Video: How To Restrict Access To Pages And Contents On WordPress 2024, May
Anonim

Sometimes it becomes necessary to restrict access to pages or any files of your site for certain groups of users. The Apache web server software has built-in tools for this task. Check them out.

How to close access to pages
How to close access to pages

Instructions

Step 1

With each request to any page on the site, the server checks for the presence of a service file named ".htaccess" in the folder where it is stored. If it is, then the server, when processing the request, will follow the directives from this file. It can also contain directives to restrict access to pages or other documents of the site on any grounds. This can be done by creating such a file in a regular text editor and uploading it to the server folder you need. Since these files are service files, they are not available from the web visitor's browser.

Step 2

To solve the access problem radically place these directives in the htaccess file: Order Deny, Allow

Deny from all Having received such instructions, the web server will close access to absolutely all files and folders in this and all its subdirectories for all visitors without exception.

Step 3

You can add an exception to the total ban for users with a specific IP address: Order Deny, Allow

Deny from all

Allow from 77.84.20.18, 77.84.21.2 In this example, users whose IP is 77.84.20.18 or 77.84.21.2 will not notice that there are any restrictions, and everyone else will not be allowed to the pages. If you need exactly this order of access - list the list of allowed IP-addresses separated by commas.

Step 4

If, on the contrary, you need to create a "black list" of unwanted IP addresses, then the directives should be changed as follows: Order Allow, Deny

Allow from all

Deny from 77.84.20.18, 77.84.21.2 Access will be closed only to visitors with IP 77.84.20.18 and 77.84.21.2, and the rest will be allowed through unhindered. And in this case, the list of banned IP addresses must be separated by commas.

Step 5

If you need to restrict access not to all documents in a folder, but only to a separate file, then the directives should look like this:

Order Deny, Allow

Deny from all

Allow from 77.84.20.18

Here, the first line contains the file to which access should be restricted (hidden.html), and the fourth line contains an exception to the deny rule - the IP of users who are allowed access to the file.

Step 6

Similarly, you can restrict access to a group of files by the mask of their names:

Order Deny, Allow

Deny from all

Allow from 77.84.20.18

Here, the first line contains a mask for the names of files with limited access - the ban will apply to all files with the "wma" extension. The fourth line, as in the previous example, contains the IP of users who are not subject to the restriction.

Step 7

It is possible to restrict access to pages by browser type - in this way, you can filter out, for example, unwanted search robots: SetEnvIfNoCase user-Agent ^ Microsoft. URL [NC, OR]

SetEnvIfNoCase user-Agent ^ Offline. Explorer [NC, OR]

SetEnvIfNoCase user-Agent ^ [Ww] eb [Bb] andit [NC, OR]

Order Allow, Deny

Allow from all

Deny from env = bad_bot

Here, the first three lines list several unwanted browser types (one for each line). Of course, when using such a design, you need to replace them with the ones that annoy your particular site.

Recommended: