htaccess - Wrong wp-admin URL

I freshly installed a WordPress site and I configured it behind a reverse proxy with site URL - ProblemI can reach the a

I freshly installed a WordPress site and I configured it behind a reverse proxy with site URL -

Problem

I can reach the admin dashboard page, however I cannot go further as the link becomes instead of . How could I get rid of this weird behaviour?

Details that might help...

  1. I am quite sure that the WordPress Address (URL) and Site Address (URL) are configured as , I even checked the database table wp_options.
  2. When it arrives the admin dashboard page with correct CSS, the browser will show the correct link for half seconds and suddenly change to the wrong one. I even checked the network log in my Chrome and Firefox, the requested URL is .
  3. I have tried to configure the .htaccess as well, but no luck.

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /hello
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /hello/index.php [L]
    </IfModule>
    # END WordPress
    

I freshly installed a WordPress site and I configured it behind a reverse proxy with site URL - http://example/hello

Problem

I can reach the admin dashboard page, however I cannot go further as the link becomes http://example/wp-admin instead of http://example/hello/wp-admin. How could I get rid of this weird behaviour?

Details that might help...

  1. I am quite sure that the WordPress Address (URL) and Site Address (URL) are configured as http://example/hello, I even checked the database table wp_options.
  2. When it arrives the admin dashboard page with correct CSS, the browser will show the correct link for half seconds and suddenly change to the wrong one. I even checked the network log in my Chrome and Firefox, the requested URL is http://example/hello/wp-admin.
  3. I have tried to configure the .htaccess as well, but no luck.

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /hello
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /hello/index.php [L]
    </IfModule>
    # END WordPress
    
Share Improve this question asked Jun 12, 2017 at 3:47 Victor WongVictor Wong 1414 bronze badges 2
  • Possibly a plugin? Try disabling them wpbeginner/plugins/… – michalzuber Commented Jun 12, 2017 at 4:47
  • Possibly nope, it is a fresh and clean install with only 2 default plugins. – Victor Wong Commented Jun 12, 2017 at 4:49
Add a comment  | 

3 Answers 3

Reset to default 3

Eventually, I found the reason of this weird behaviour.

It is caused by the JavaScript embedded in wp_admin_canonical_url() (https://developer.wordpress/reference/functions/wp_admin_canonical_url/)

The URL is determined by this piece of code

$_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']

where the latter one returns wp-admin instead of hello/wp-admin.

By manipulating the value in $_SERVER['REQUEST_URI'], I can successfully get the correct behaviour in admin dashboard. But I still hope for an elegant solution without touching WordPress code.

add_filter('set_url_scheme', 'hacky_uri_fix', 10, 2);
function hacky_uri_fix($url, $scheme) {
    if ( $url === {{BAD ADMIN URL}} ) {
        $url = {{CORRECT ADMIN URL}}
    }
    return $url
}

should work, just replace the bad URL you are trying to avoid with the correct one. I'm sure there's a better solution to this out there but I'm not super familiar with subfolder installs and this should work without touching core code.

Victor is 100%, so save the next person (maybe even myself) work digging further:

  • the function wp_admin_canonical_url is in the ./wp-admin/includes/misc.php file
  • Change

    $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']

to be

$_SERVER['HTTP_HOST'] . '/news/. $_SERVER['REQUEST_URI']

Where /news can be anything you have as a path in front of the wp-admin folder.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744902529a4600060.html

相关推荐

  • htaccess - Wrong wp-admin URL

    I freshly installed a WordPress site and I configured it behind a reverse proxy with site URL - ProblemI can reach the a

    1天前
    50

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信