I would like to redirect zombay.org/wp-admin to my index and make the WP-Admin accessible though something like zombay.org/admin. I did this in apache but after switching to nginx I don’t know how to do this. Is there a way to do this without changing any of the wordpress files but changing the nginx config ?
Any help is appreciated, thanks.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
I haven’t tested this solution thoroughly, so please check if it works for you.
Edit the wp-config.php file and place the following:
define('WP_ADMIN_DIR', 'admin');
define('ADMIN_COOKIE_PATH', SITECOOKIEPATH . WP_ADMIN_DIR);
Create a mu-plugins directory:
mkdir wp-content/mu-plugins
Create a file inside it and place the following code. Let’s name this file admin-rewrite.php
<?php
add_filter( 'site_url', 'wpadmin_filter', 10, 3 );
function wpadmin_filter( $url, $path, $orig_scheme ) {
return preg_replace( "/(wp-admin)/", WP_ADMIN_DIR, $url, 1 );
}
add_action( 'login_form', 'redirect_wp_admin' );
function redirect_wp_admin(){
$redirect_to = $_SERVER['REQUEST_URI'];
if ( count( $_REQUEST ) > 0 && array_key_exists( 'redirect_to', $_REQUEST ) ) {
$check_wp_admin = stristr( $_REQUEST['redirect_to'], 'wp-admin' );
if( $check_wp_admin ) {
wp_redirect( home_url() );
exit;
}
}
}
Edit the Nginx virtual host file and place the following:
location ~* /admin/ {
rewrite ^/admin/(.*) /wp-admin/$1 last;
}
Do a configtest and reload.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.