Categories

Featured templates

12 most useful .WordPress的htaccess技巧

Carey Burns June 13, 2018
Rating: 5.0/5. From 2 votes.
Please wait...

大家好,我们的支持团队准备为大家呈现一个新的教程 12 most useful .htaccess tricks for WordPress.

The .htaccess File是一个服务器配置文件,它允许您为您的服务器定义要遵循的规则 website.

WordPress usually uses .htaccess file to generate SEO friendly URLs. 但是,这个文件可以用于其他各种目的.

The .htaccess 文件位于您的WordPress站点的 root folder. 你需要连接到你的 website using an FTP client to edit it.

  1. 保护你的WordPress管理区

    只需将此代码复制并粘贴到 .htaccess file:

    AuthUserFile /dev/null
    AuthGroupFile /dev/null
    AuthName“WordPress Admin Access Control”
    AuthType Basic
    
    order deny,allow
    deny from all
    #白名单Syed的IP地址
    allow from xx.xx.xx.xxx
    #白名单大卫的IP地址
    allow from xx.xx.xx.xxx
    
    

    您需要用自己的值替换xx值 IP address

  2. 密码保护WordPress Admin文件夹

    You can use .htaccess 文件添加一个额外的密码保护到你的WordPress管理区域.

    1. 首先,您需要生成一个 .htpasswds file. 你可以用这个来做 online generator.

    2. Upload this .htpassds文件在您的公开访问的web之外 directory or /public_html/ folder. For example: /public_html/wp-admin/passwd/

    3. Create a .htaccess 文件并上传到/wp-admin/ directory 然后在这里添加以下代码:

      AuthName "Admins Only"
      AuthUserFile /home/yourdirectory /.htpasswds / public_html / wp-admin / passwd
      AuthGroupFile /dev/null
      AuthType basic
      要求用户把你的用户名放在这里
      
      Order allow,deny
      Allow from all
      Satisfy any 
      
      
    4. 将AuthUserFile路径替换为您的 .htpassds文件并添加您自己的用户名

  3. Disable Directory Browsing

    To disable directory browsing on your website,您需要将以下行添加到 .htaccess file:

    Options -Indexes
    
  4. 在某些WordPress目录中禁用PHP执行

    您可以通过禁用某些WordPress目录的PHP执行来提高WordPress的安全性. 您需要创建一个空的 .htaccess 文件,然后将以下代码粘贴到其中:

    
    deny from all
    
    
  5. 保护你的WordPress配置.php File

    以保护您的wp-config.PHP文件从未经授权的访问,只需添加以下代码到您的 .htaccess file:

    
    order allow,deny
    deny from all
    
    
  6. 设置301重定向 .htaccess File

    使用301重定向是最多的 SEO 友好的方式告诉您的用户,内容已移动到新的位置. 可以通过添加以下代码来设置重定向 .htaccess file:

    重定向301 /oldurl/ http://www.example.com/newurl
    重定向301 /类别/电视/ 
    http://www.example.com/category/tv/
    
  7. 禁止可疑IP地址

    将以下代码添加到您的 .htaccess file. 别忘了把xx换成 IP address you want to block.

    
    order allow,deny
    deny from xxx.xxx.xx.x
    allow from all
    
    
  8. 禁用图片热链接在WordPress使用 .htaccess

    可以通过将此代码添加到您的 .htaccess file:

    禁用带有禁用或自定义图像选项的图像的热链接
    RewriteEngine on
    RewriteCond % {HTTP_REFERER} !^$
    RewriteCond % {HTTP_REFERER} !^http(s)?://(www\.)?wpbeginner.com [NC]
    RewriteCond % {HTTP_REFERER} !^http(s)?://(www\.)?google.com [NC]
    RewriteRule \.(jpg|jpeg|png|gif)$ - [NC,F,L] 
    
  9. Protect .htaccess From Unauthorized Access

    由于它在您的web服务器上的权力和控制, 保护它免受黑客未经授权的访问是很重要的. 只需将以下代码添加到 .htaccess file:

    
    order allow,deny
    deny from all
    satisfy all
    
    
  10. 在WordPress中增加文件上传大小

    可以通过将以下代码添加到 .htaccess file:

    php_value upload_max_filesize 64M
    php_value post_max_size 64M
    Php_value max_execution_time 300
    Php_value max_input_time 300
    
  11. Disable Access to XML-RPC File Using .htaccess

    有多种方法可以做到这一点,其中之一是将以下代码添加到您的 .htaccess file:

    # Block WordPress xmlrpc.php requests
    
    order deny,allow
    deny from all
    
    
  12. 在WordPress中阻止作者扫描

    在暴力攻击中使用的一种常用技术是在WordPress站点上运行作者扫描,然后尝试破解这些用户名的密码. 您可以通过将以下代码添加到您的 .htaccess file:

    #开始块作者扫描
    RewriteEngine On
    RewriteBase /
    rewritecsecond %{QUERY_STRING}(作者=\d+) [NC]
    RewriteRule .* - [F]
    #结束块作者扫描 
    

Browse the selection of WordPress Themes 查看最新设计并了解更多WordPress功能.

Cool Wordpress Themes
这个条目被张贴了出来 Monstroid Tutorials, WordPress Tutorials and tagged .htaccess, files. Bookmark the permalink.

Submit a ticket

如果您仍然无法找到关于您的问题的足够的教程,请使用以下链接向我们的技术支持团队提交请求. 我们将在接下来的24小时内为您提供我们的帮助和协助: Submit a ticket