douli1306 2019-06-10 18:57
浏览 51

拒绝所有php文件,但允许特定文件夹与php文件

I want to deny access to all PHP files in all subfolders, but allow access to all PHP files in a specific subfolder (e.g. test).

I tried a lot, but cannot find any solution.

Here is the whole htaccess file

<filesmatch \.(php|phtml)$>
    deny from all
</filesmatch>
<filesmatch (index.php|install.php)>
    allow from all
</filesMatch>
<ifmodule mod_deflate.c>
    <filesmatch \.(css|js|php|phtml|svg|woff|xml)$>
        setoutputfilter deflate
    </filesmatch>
</ifmodule>
<ifmodule mod_security.c>
    secfilterengine off
    secfilterscanpost off
</ifmodule>
<ifmodule mod_rewrite.c>
    rewriteengine on
    rewritecond %{https} off
    rewritecond %{http_host} ^www\.(.*)$ [nc]
    rewriterule ^(.*)$ http://%1/$1 [r=301,l]
    rewritecond %{https} on
    rewritecond %{http_host} ^www\.(.*)$ [nc]
    rewriterule ^(.*)$ https://%1/$1 [r=301,l]
    rewritecond %{request_filename} !-d
    rewriterule ^(.*)/$ /$1 [r=301,l]
    rewritecond %{request_filename} -f
    rewriterule ^(.*) $1 [l]
    rewritecond %{request_filename} !-d
    rewriterule ^([^.]*)$ ?p=$1 [l]
    rewritecond %{request_filename} !-d
    rewriterule ^([^.]*).([\w]{2})$ ?p=$1&l=$2 [l]
    rewritecond %{request_filename} !-d
    rewriterule ^([^.]*).([\w]{3,})$ ?p=$1&t=$2 [l]
</ifmodule>
<ifmodule mod_headers.c>
    <filesmatch \.(gif|ico|jpg|svg|png|woff)$>
        header set cache-control max-age=2419200
    </filesmatch>
    <filesmatch \.(css|js|swf)$>
        header set cache-control max-age=604800
    </filesmatch>
    <filesmatch \.(phtml|xml)$>
        header set cache-control max-age=600
    </filesmatch>
</ifmodule>
fileetag none

Thanks!

  • 写回答

1条回答 默认 最新

  • doujiaochan7317 2019-06-11 03:50
    关注

    In a system I coded, I added the following line to the codes, which I only want them to be accessible by those which I want them to access:

    defined('AUTH') or die(header('HTTP/1.0 403 Forbidden'));
    

    And for those .php files, if I want them to use/access that particular PHP script, I started them by adding this line onto the top before I include() or require() the files:

    define('AUTH', true);
    

    This way, any access attempt to those files that do not have "AUTH" defined in it will get an HTTP 403. This also forbids direct link access. ;) Maybe this solution works for you, too.

    评论

报告相同问题?

悬赏问题

  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私