-
-
Save mcguffin/b0ab861e90dfe81a22c5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Change Admin URL | |
* | |
* Copyright (C) 2010 hakre <http://hakre.wordpress.com/> | |
* | |
* This program is free software: you can redistribute it and/or modify | |
* it under the terms of the GNU Affero General Public License as | |
* published by the Free Software Foundation, either version 3 of the | |
* License, or (at your option) any later version. | |
* | |
* This program is distributed in the hope that it will be useful, | |
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
* GNU Affero General Public License for more details. | |
* | |
* You should have received a copy of the GNU Affero General Public License | |
* along with this program. If not, see <http://www.gnu.org/licenses/>. | |
* | |
* USAGE: | |
* | |
* Copy the file into wp-content/mu-plugins directory and add the | |
* following RewriteRule to your apache configuration or .htaccess: | |
* | |
* RewriteRule ^admin/(.*)$ wp-admin/$1 [QSA,L] | |
* | |
* It will rewrite the wordpress admin-URL | |
* | |
* from: http://example.com/wp-admin/ ... | |
* to : http://example.com/admin/ ... | |
* | |
* @author hakre <http://hakre.wordpress.com> | |
* @see http://wordpress.stackexchange.com/questions/4037/how-to-redirect-rewrite-all-wp-login-requests/4063 | |
* @todo mod_rewrite_rules - filter to insert into .htacces on plugin activation | |
*/ | |
return ChangeAdminUrlPlugin::bootstrap(); | |
class ChangeAdminUrlPlugin { | |
private $renameFrom = 'wp-admin'; | |
private $renameTo = 'admin'; | |
private $first_run = false; | |
static $instance; | |
static public function bootstrap() { | |
null === self::$instance | |
&& self::$instance = new self() | |
; | |
return self::$instance; | |
} | |
private function setCookiePath() { | |
defined('SITECOOKIEPATH') || define('SITECOOKIEPATH', preg_replace('|https?://[^/]+|i', '', get_option('siteurl') . '/' ) ); | |
defined('ADMIN_COOKIE_PATH') || define('ADMIN_COOKIE_PATH', SITECOOKIEPATH . $this->renameTo); | |
} | |
public function __construct() { | |
$this->first_run = ! get_option('change_admin_url_present'); | |
if ( $this->first_run ) { | |
add_action('admin_init', array($this, 'admin_init')); | |
} else { | |
add_action('init', array($this, 'init')); | |
$this->setCookiePath(); | |
} | |
} | |
public function init() { | |
add_filter('admin_url', array($this, 'admin_url'), 10, 3); | |
} | |
public function admin_url($url, $path, $blog_id) { | |
$renameFrom = $this->renameFrom; | |
$renameTo = $this->renameTo; | |
$scheme = 'admin'; | |
$find = get_site_url($blog_id, $renameFrom.'/', $scheme); | |
$replace = get_site_url($blog_id, $renameTo.'/', $scheme); | |
(0 === strpos($url, $find)) | |
&& $url = $replace.substr($url, strlen($find)) | |
; | |
return $url; | |
} | |
public function admin_init() { | |
add_rewrite_rule("admin/(.*)", 'wp-admin/$1'); | |
flush_rewrite_rules( true ); | |
update_option('change_admin_url_present',1); | |
$this->init(); | |
wp_redirect( admin_url() ); | |
} | |
} | |
#EOF; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, for me not work. I have symlinked wordpress in path /wordpress/. Multisite setup. I get "ERR_TOO_MANY_REDIRECTS". In browser I have right url "some.loc/website/admin/". "some.loc/admin/" works perfect, also in network site (via filter 'network_admin_url').
My htaccess is following: