[wp-trac] [WordPress Trac] #15289: Make it easier for a non-standard URL to be used to access wp-admin
WordPress Trac
wp-trac at lists.automattic.com
Tue Nov 9 12:22:57 UTC 2010
#15289: Make it easier for a non-standard URL to be used to access wp-admin
-----------------------------+----------------------------------------------
Reporter: caesarsgrunt | Owner:
Type: feature request | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Administration | Version: 3.1
Severity: normal | Keywords:
-----------------------------+----------------------------------------------
Comment(by caesarsgrunt):
Ok... here is the code I've used for this in the past. Two parts, one in a
plugin and one in .htaccess. This code also changes example.com/wp-login
to example.com/login.[[BR]]
A few function and variable names have been changed to protect the
identity of my client, but the functionality is the same.
'''In a plugin :'''[[BR]]
{{{
/**
* HACK : Change admin urls to /admin/ instead of /wp-admin/.
* Only works in conjunction with some complex rules in .htacces.
*/
function caesarsgrunt_admin_url($url, $path) {
return str_ireplace('/wp-admin/', '/admin/', $url);
}
add_filter('admin_url', 'caesarsgrunt_admin_url', 10, 2);
add_filter('network_admin_url', 'caesarsgrunt_admin_url', 10, 2);
/**
* HACK : Change login/out urls to /login/ instead of /wp-login.php.
* Only works in conjunction with some rules in .htacces.
*/
function caesarsgrunt_login_url($url) {
return str_ireplace('/wp-login.php', '/login/', $url);
}
add_filter('login_url', 'caesarsgrunt_login_url', 10, 1);
add_filter('logout_url', 'caesarsgrunt_login_url', 10, 1);
add_filter('site_url', 'caesarsgrunt_login_url', 10, 1); // because wp-
login.php uses this when linking to itself
add_filter('network_site_url', 'caesarsgrunt_login_url', 10, 1); //
because wp-login.php uses this when emailing the user
/**
* HACK : Prevent redirect from /login/ to /login/wp-login.php.
* Part of the /login/ hack. After logging the user out, wp-login.php
redirects to itself using a hard-coded url.
* This results in a redirect from /login/ to /login/wp-login.php.
* Here we prevent that by catching the redirect and changing it to
/login/.
*/
function caesarsgrunt_wp_redirect($url, $status) {
return str_ireplace('wp-login.php', '/login/', $url);
}
add_filter('wp_redirect', 'caesarsgrunt_wp_redirect', 10, 2);
}}}
'''In .htaccess :''' (may be buggy, I'm not an htaccess expert, but it
works fine)[[BR]]
{{{
# 301 redirect /wp-admin/ to /admin/
# infinite loop avoided with the second cond
# NE prevents re-encoding query vars, which are likely to already be
encoded
RewriteCond %{HTTP_ACCEPT} text/html
#RewriteCond %{THE_REQUEST} ^GET\ (.*)/wp-admin/
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin/(.*)$ $1admin/$2 [R,L,NE]
# internally redirect /admin/ to /wp-admin/ - if the file exists in the
latter
RewriteCond %{DOCUMENT_ROOT}/wp-admin/$1 -f [OR]
RewriteCond %{DOCUMENT_ROOT}/wp-admin/$1 -d
RewriteRule admin/(.*)$ wp-admin/$1
# internally redirect /login/ to /wp-login.php
RewriteRule login/$ wp-login.php
# add a trailing slash to /admin and /login
RewriteRule ^([_0-9a-zA-Z-]+/)?admin$ $1admin/ [R=301,L]
RewriteRule ^([_0-9a-zA-Z-]+/)?login$ $1login/ [R=301,L]
# remove multiple slashes anywhere in the url
RewriteCond %{REQUEST_URI} ^(.*)//(.*)$
RewriteRule . %1/%2 [R=301,L]
}}}
--
Ticket URL: <http://core.trac.wordpress.org/ticket/15289#comment:3>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list