简体   繁体   中英

Allow direct access for specific php file

Rule bellow should block any direct access to all *.php files:

RewriteCond %{THE_REQUEST} ^.+?\ [^?]+\.php[?\ ]
RewriteRule \.php$ - [F]

Is there a way to exclude 1 or 2 php files to be ignored by this global rule?

example:

all *.php files (ignored if accessed directly)

cronjob.php, specialpage.php (should be ignored by the rule above and direct access should be allowed.)

can you please show example of (1) or (2 or more) files excluded.

PS: if such rule to exclude those files exists, what flag needs to be applied? [L] or [R,L] or ????

You can use negation in RewriteRule :

RewriteCond %{THE_REQUEST} ^.+?\ [^?]+\.php[?\ ] [NC]
RewriteRule !(^|/)(cronjob|specialpage)\.php$ - [F,NC]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM