本文介绍了隐藏 wp-admin 使用 htaccess的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用.htaccess文件把wp-admin改成admin_panel,访问链接admin_panel时显示wp-admin的内容,但是访问链接wp-admin时提示找不到

I want to change wp-admin to admin_panel using .htaccess file and when visit link admin_panel, it displays the contents of wp-admin, but when visit link wp-admin, it will notice not found

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /cms/wp/
RewriteRule ^index\.php$ - [L]
RewriteRule ^admin_panel/(.*) /cms/wp/wp-admin/$1 [QSA,L]
RewriteRule ^wp-admin /cms/wp/nothing_404_404 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /cms/wp/index.php [L]
</IfModule>

# END WordPress

它不起作用,所有 url wp-admin 或 admin_panel 结果都没有找到.

It not working, all url wp-admin or admin_panel result not found both.

推荐答案

我不知道您为什么只尝试使用 .htaccess 文件来完成此操作,但让我向您展示更改管理目录的正确方法.

I have no idea why you are trying to accomplish this only using .htaccess file but let me show you the correct way to change the admin directory.

如果您希望仅使用 .htaccess 文件完成它的具体原因,请告诉我,但我什至不确定是否可行.

If there is a specific reason why you want it to be done only using .htaccess file please let me know however I am not even sure if it is possible.

步骤:

  1. 添加常量到wp-confing.php

define('WP_ADMIN_DIR', '**admin_panel**');
define('ADMIN_COOKIE_PATH', SITECOOKIEPATH . WP_ADMIN_DIR); 

  • 将以下过滤器添加到functions.php

  • Add below filter to functions.php

    add_filter('site_url',  'wpadmin_filter', 10, 3);    
    function wpadmin_filter( $url, $path, $orig_scheme ) {    
        $old  = array( "/(wp-admin)/");    
        $admin_dir = WP_ADMIN_DIR;     
        $new  = array($admin_dir);    
        return preg_replace( $old, $new, $url, 1);   
    }
    

  • 在 .htaccess 文件中添加以下行

  • Add below line to .htaccess file

    RewriteRule ^admin_panel/(.*) wp-admin/$1?%{QUERY_STRING} [L]
    

  • 大功告成.

    现在您的管理员 URL 将类似于:http://www.yourdomain.com/admin_panel/

    Now your admin URL will be like: http://www.yourdomain.com/admin_panel/

    希望对您有所帮助.

    这篇关于隐藏 wp-admin 使用 htaccess的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

    10-20 23:05