Wordpress、php、またはApacheで/wp-admin
を含むすべてのURLを/admin
に書き換える簡単な方法はありますか?
このエントリを自分の.htaccessファイルに追加しました。
RewriteRule ^admin /wp-login.php [L]
しかしdomain.com/admin
はログインページを正しく表示しますが、ログイン後のすべてのページはURLを/wp-admin
として表示します。これは常に/admin
を表示したいものです。
これについて何か考え?
mod_rewrite (URLの書き換えを処理するApacheモジュール)を介したApache URLレイアウト構成としての質問に答えるには、これが役立ちます。
RewriteRule ^admin/(.*)$ /wp-admin/$1 [QSA,L]
(テストされていない設定ディレクティブ、これがエラーになる場合に備えてドキュメントをチェックしてください)
これは基本的に/ admin/...への要求を/ wp-admin/...に変換します。
それだけが知りたいのであれば、これはworpdress @ seでは少し話題から外れていることを認めなければなりません。これは実際にはApache Webサーバの設定方法に関する質問だからです。より良い場所は serverfault かもしれません。
これはリクエストされたURLのみを書き換えることに注意してください。 Wordpressはこれについて何も知らないであろう、そしてそれはそれでも管理者の/ wp-admin /へのリンクを出力する。あなたがその時同様に書き直すことを望むかもしれないどんな管理者URLのためのフックもあります:
return apply_filters('admin_url', $url, $path, $blog_id);
あなたはdomain/wp-admin/
の部分をdomain/admin/
にあなた自身のフィルタで置き換える必要があるでしょう。
hakre ....素晴らしい答え...今、私はあなたの解決策を使い、同じ方法で正しく "Network Admin"リンクを書き直すために部分に加えられた別のネットワーク管理者を持っているワードプレスの最新版で….
/**
* 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
*
*/
/** Updated version my Mark Figueredo, <http://gruvii.com/> **/
return ChangeAdminUrlPlugin::bootstrap();
class ChangeAdminUrlPlugin {
private $renameFrom = 'wp-admin';
private $renameTo = 'admin';
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->setCookiePath();
add_action('init', array($this, 'init')) ;
}
public function init() {
add_filter('admin_url', array($this, 'admin_url'), 10, 3);
add_filter('network_admin_url', array($this, 'network_admin_url'), 10, 3);//Added by Mark Figueredo, <http://gruvii.com/>
}
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;
}
// Added by Mark Figueredo, <http://gruvii.com/>
public function network_admin_url($url, $path) {
$renameFrom = $this->renameFrom;
$renameTo = $this->renameTo;
$scheme = 'admin';
$find = network_site_url($renameFrom.'/', $scheme);
$replace = network_site_url($renameTo.'/', $scheme);
(0 === strpos($url, $find))
&& $url = $replace.substr($url, strlen($find))
;
return $url;
}
}
以前の解決策に加えて。足りないcssファイルとスクリプトファイルが見つかりました。
修正は
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
# uploaded files
RewriteRule ^([_0-9a-zA-Z-]+/)?files/(.+) wp-includes/ms-files.php?file=$2 [L]
# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]
# Fix using the previous answer.
RewriteRule ^admin/(.*)$ wp-admin/$1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^[_0-9a-zA-Z-]+/(wp-(content|admin|includes).*) $1 [L]
#Fix to load css js image files for multi site admin urls.
#old code RewriteRule ^[_0-9a-zA-Z-]+/(.*\.php)$ $1 [L]
RewriteRule ^[_0-9a-zA-Z-]+/(.*\.(php|css|js|png|jpg|gif))$ $1 [L]
RewriteRule . index.php [L]