允许直接访问特定的php文件

时间:2021-09-19 03:20:02

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

规则bellow应该阻止对所有* .php文件的任何直接访问:

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?

有没有办法排除1或2个php文件被这个全局规则忽略?

example:

all *.php files (ignored if accessed directly)

所有* .php文件(如果直接访问则忽略)

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

cronjob.php,specialpage.php(应该被上面的规则忽略,应该允许直接访问。)

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

你能否请出示(1)或(2个或更多)文件的例子。

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

PS:如果存在排除这些文件的规则,需要应用哪个标志? [L]或[R,L]或????

1 个解决方案

#1


2  

You can use negation in RewriteRule:

你可以在RewriteRule中使用否定:

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

#1


2  

You can use negation in RewriteRule:

你可以在RewriteRule中使用否定:

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