user4805223
user4805223

Reputation: 3

Rewrite_rule to protect files in directory

How do I add some conditions to my htaccess so that if I enter :

http://example.com/protectedpage.php

It redirect to:

http://example.com/no_access.php

Here is a list of files that I would like to protect from users:

protectedpage1, protectedpage2, protectedpage3,...

How do I achive it?

Upvotes: 0

Views: 137

Answers (2)

anubhava
anubhava

Reputation: 785561

You can use regex alternation and have a simple RedirectMatch rule like this:

RedirectMatch ^/(protectedpage1|protectedpage2|protectedpage3)\.php$ /no_access.php

Upvotes: 0

Amit Verma
Amit Verma

Reputation: 41219

Try this in your Root/.htaccess file

 RewriteEngine On 
 RewriteBase / 
 RewriteCond %{REQUEST_URI} ^/protectedpage1\.php [OR] 
 RewriteCond %{REQUEST_URI} ^/protectedpage2\.php [OR] 
 RewriteCond %{REQUEST_URI} ^/protectedpage3\.php
 RewriteRule .* /no_access.php [L,R] 

RewriteConditions check if the Requested URI string contains any of the spacified files then Server will redirect them to the no_access.php page.

Upvotes: 1

Related Questions