dtotuki47568 2013-11-10 19:25
浏览 81
已采纳

WordPress是否需要根文件夹中的完整index.php? 有没有更好的方法来防止黑客入侵?

Not a programmer or PHP expert here: please assume entry-level knowledge.

For security reasons, I'd like to allocate the contents of the index.php in my main WordPress folder to something else -- say, fish.php and just have an index.php that calls it, like so:

<html>
<body>

<?php include 'fish.php'; ?>

</body>
</html>

The fish.php file would contain everything that's usually in index.php. It would just be named fish.php.

Will this completely break WordPress? Is a full, detailed index.php file absolutely necessary for it to function, or is it a one-time "load and go" php file that isn't referred to again once WP is in the browser?

  • 写回答

1条回答 默认 最新

  • doujiao9866 2013-11-10 19:35
    关注

    Your question is confusing. So you want another file that then includes the contents of index.php in WordPress? What are you trying to achieve? The basic gist of your question seems to be this line:

    Is a full, detailed index.php file absolutely necessary for it to function, or is it a one-time "load and go" php file that isn't referred to again once WP is in the browser?

    The way content management systems—or virtually any controller based system—works is to flitter all request in one file & then act on them. In WordPress, that is index.php. And it does more than just load the homepage. It’s the gateway page to all other pages. So you can muck around with it, but why? And for what benefit?

    EDIT: The original poster in the comments to my answer explains that they are thinking of ways to prevent a WordPress site from being hacked. Renaming a file will not work. Especially since index.php is only seen on the server side. Let’s say by some crazy config the original poster adjusts Apache to always load fish.php as their index. The web browser—and users & bots—will still get WordPress content. Instead I do the following as a slid brute-force way of avoiding hacks: I place .htaccess password protection on the admin areas of CMS systems. The logic being—and it has worked so far—that most CMS systems are attacked by scripts that hack vulnerabilities in the admin or login process. Yes, some bots might get through. But you can eliminate tons of “low hanging fruit” with this method.

    For example, below is part of the Apache virtual host config that I will use as an example for a site I am calling mygreatsite.com that I have based in the standard /var/www. Note that I am adding authorization for wp-login.php and wp-admin but allowing admin-ajax.php to pass since many functions use it. Now users who administer the site will need to remember an additional—somewhat generic—htpasswd_wordpress_admin user/password combination on top of their standard WordPress credentials. But guess what? Most CMS hacking scripts give up when faced with a browser based password coming from Apache like this.

      # Added for WordPress CMS protection.
      <Directory /var/www/mygreatstite.com/wordpress/wp-login.php>
        Options FollowSymLinks
        AllowOverride all
    
        AuthName "WordPress Login"
        AuthType Basic
        require valid-user
        AuthUserFile /etc/apache2/htpasswd_wordpress_admin
    
        Order Deny,Allow
        Deny from all
        Satisfy Any
      </Directory>
    
      # Added for WordPress CMS protection.
      <Directory /var/www/mygreatstite.com/wordpress/wp-admin>
        Options FollowSymLinks
        AllowOverride all
    
        AuthName "WordPress Admin"
        AuthType Basic
        require valid-user
        AuthUserFile /etc/apache2/htpasswd_cms_admin
    
        Order Deny,Allow
        Deny from all
    
        # Allow 'admin-ajax.php' to pass.
        <Files admin-ajax.php>
          # Order Allow,Deny
          Allow from all
        </Files>
    
        Satisfy Any
    
      </Directory>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 PointNet++的onnx模型只能使用一次
  • ¥20 西南科技大学数字信号处理
  • ¥15 有两个非常“自以为是”烦人的问题急期待大家解决!
  • ¥30 STM32 INMP441无法读取数据
  • ¥15 R语言绘制密度图,一个密度曲线内fill不同颜色如何实现
  • ¥100 求汇川机器人IRCB300控制器和示教器同版本升级固件文件升级包
  • ¥15 用visualstudio2022创建vue项目后无法启动
  • ¥15 x趋于0时tanx-sinx极限可以拆开算吗
  • ¥500 把面具戴到人脸上,请大家贡献智慧,别用大模型回答,大模型的答案没啥用
  • ¥15 任意一个散点图自己下载其js脚本文件并做成独立的案例页面,不要作在线的,要离线状态。