最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

url rewriting - Prevent wp-admin from redirecting to homepage?

programmeradmin1浏览0评论

I have copied a wordpress instance from production to my local. After getting the public side of the site up - public homepage, pages, and blog posts -, I cannot access /wp-admin/ because that url always redirects to the / homepage. I have tried:

  • Updating the siteurl and home to "" (homepage and posts work fine)
  • Implementing a local self-signed ssl cert (in case it was an https problem.)
  • Switched to 2019 theme (theme works, but problem still persists)
  • Setting debug constants in wp-config.php
  • Removing debug constants in wp-config.php
  • Moved the plugins directory aside, replaced with /plugins containing only index.php

Here is a curl of wp-admin:

curl -Ik /wp-admin/
HTTP/1.1 301 Moved Permanently
Server: nginx/1.16.0
Date: Wed, 24 Jul 2019 17:27:39 GMT
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
X-Powered-By: PHP/5.6.40
X-Redirect-By: WordPress
Location: /
Last-Modified: Wed, 24 Jul 2019 17:27:39 GMT
Expires: Wed, 24 Jul 2019 18:27:39 GMT
Pragma: public
Cache-Control: max-age=3600, public
ETag: "d41d8cd98f00b204e9800998ecf8427e"
Strict-Transport-Security: max-age=63072000; includeSubdomains
X-Frame-Options: DENY
X-Content-Type-Options: nosniff
X-uri: /wp-admin/

Obviously on the production copy the wp-admin url works. Throughout it all, it 301 redirects from /wp-admin to / How can I prevent it from redirecting?

I have copied a wordpress instance from production to my local. After getting the public side of the site up - public homepage, pages, and blog posts -, I cannot access /wp-admin/ because that url always redirects to the / homepage. I have tried:

  • Updating the siteurl and home to "https://tk.local" (homepage and posts work fine)
  • Implementing a local self-signed ssl cert (in case it was an https problem.)
  • Switched to 2019 theme (theme works, but problem still persists)
  • Setting debug constants in wp-config.php
  • Removing debug constants in wp-config.php
  • Moved the plugins directory aside, replaced with /plugins containing only index.php

Here is a curl of wp-admin:

curl -Ik https://tk.local/wp-admin/
HTTP/1.1 301 Moved Permanently
Server: nginx/1.16.0
Date: Wed, 24 Jul 2019 17:27:39 GMT
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
X-Powered-By: PHP/5.6.40
X-Redirect-By: WordPress
Location: https://tk.local/
Last-Modified: Wed, 24 Jul 2019 17:27:39 GMT
Expires: Wed, 24 Jul 2019 18:27:39 GMT
Pragma: public
Cache-Control: max-age=3600, public
ETag: "d41d8cd98f00b204e9800998ecf8427e"
Strict-Transport-Security: max-age=63072000; includeSubdomains
X-Frame-Options: DENY
X-Content-Type-Options: nosniff
X-uri: /wp-admin/

Obviously on the production copy the wp-admin url works. Throughout it all, it 301 redirects from https://tk.local/wp-admin to https://tk.local/ How can I prevent it from redirecting?

Share Improve this question edited Jul 29, 2019 at 20:03 Kzqai asked Jul 24, 2019 at 17:23 KzqaiKzqai 1131 silver badge11 bronze badges 4
  • 1 Have you disabled all your plugins on tk.local and switched to a default theme? What does the .htaccess file look like on tk.local? When you say you tried Updating the siteurl and home to "tk.local", did you set them to tk.local or https://tk.local? – Pat J Commented Jul 29, 2019 at 18:40
  • 1 @PatJ Yes. I moved the plugins directory away and replaced it with a clean install version that just contains index.php, still redirects. No .htaccess, I am using nginx without any redirections that list wp-admin. Yes, the siteurl and home setting are set to https. – Kzqai Commented Jul 29, 2019 at 20:01
  • 2 Does there happen to be an .htaccess file within the wp-admin folder? Have you tried starting with a fresh copy of WordPress and copying in the wp-content folder from the production site? – socki03 Commented Jul 29, 2019 at 20:35
  • @socki03 Your idea to replace the outer source code make it clear that since the source was identical to wordpress 5, it had to be my nginx config. I wouldn't have thought of just wiping all the non wp-content source code temporarily, but it was helpful. If you want to make it an answer, I'd look at giving that the bounty. – Kzqai Commented Jul 29, 2019 at 23:15
Add a comment  | 

3 Answers 3

Reset to default 3

In my case, it ended up being some kind of adverse interaction in the nginx wordpress config that I had. Something about not passing along the naked arguments:

        location / {
original line:               try_files $uri @php;
new line:        try_files $uri $uri/ /index.php?$args;
        }

And the associated upstream was wrong. Used the config suggested here: https://www.nginx/resources/wiki/start/topics/recipes/wordpress/ For a simpler wordpress nginx config and that solved it.

Please try going into the local database and looking in the options table for the home and site url. Make sure these values correctly reference the local site URL.

Alternatively, in your local wp-config.php file you could try defining the home and site url constants like this:

define( 'WP_HOME', 'http://example' );
define( 'WP_SITEURL', 'http://example' );
  • Look into .htaccess, there might be set some specific urls/directories, which you might need to remove/change, like:

    RewriteBase /subdir/

  • Also, in phpmyadmin, check wp-options first and second rows, there should be needed similarly modified site-url .

  • If MultiSite, then change that in wp-config too.

发布评论

评论列表(0)

  1. 暂无评论