team
team

Reputation: 59

how to disable php file direct access based on url, for particular subfolders only

Problem with htaccess files permission.

I have few files with .php extension in root folder which can be accessed in website as example.com/myprofile.php

I have another file(myprofileservice.php) in directory(service) as: example.com/service/myprofileservice.php

This myprofileservice.php will provide necessary information from backend when url: example.com/myprofile.php is accessed in browser.

I want to disable viewing php files but only for directory "service" not the root.

Preventing .php file access by rule

RewriteRule .*\.(php)$ - [F,NC]

prevents the example.com/myprofile.php itself to load , which is incorrect

Upvotes: 2

Views: 391

Answers (1)

Amit Verma
Amit Verma

Reputation: 41219

Try :

RewriteRule ^service/myprofileservice.php$ - [F,L]

This will forbid access to a single php file service/myprofileservice.php .

Upvotes: 1

Related Questions