简体   繁体   English

wp-admin 或 wp-login.php 上的重定向循环

[英]Redirect loop on wp-admin or wp-login.php

I put together a quick WordPress site locally using MAMP, then checked it into an SVN repo.我使用 MAMP 在本地建立了一个快速的 WordPress 站点,然后将它签入一个 SVN 存储库。 I then checked it out on to my development server.然后我将其检查到我的开发服务器上。

I didn't change anything except to run the search and replace tool script from Interconnectit to updated the URL of the site in the database on the server.除了从 Interconnectit 运行搜索和替换工具脚本以更新服务器数据库中站点的 URL 之外,我没有做任何更改。

Initially, I got a 500 server error.最初,我收到了 500 服务器错误。 Checking the logs, I discovered that this "SoftException" was because index.php was writeable by group - the permissions were 664. No problem - a quick change of permissions to 644 sorted that.检查日志,我发现这个“SoftException”是因为index.php按组写入 - 权限是 664。没问题 - 将权限快速更改为 644 可以排序。 So now the frontside was working.所以现在前端正在工作。

However, strangely, the admin side of the site did not work.然而,奇怪的是,该站点的管理端不起作用。 It just produced an endless redirect loop in all browsers.它只是在所有浏览器中产生了无限的重定向循环。

Error 310 (net::ERR_TOO_MANY_REDIRECTS): There were too many redirects.

Nothing has changed since the local development version.自本地开发版本以来没有任何变化。 The htaccess file is just a standard WordPress one. htaccess 文件只是一个标准的 WordPress 文件。 Nothing weird... still working fine locally.没什么奇怪的......在本地仍然可以正常工作。

So what's going on?发生什么了?

For whatever reason /wp-admin/ path causes a redirect loop, but /wp-admin/index.php does not.无论出于何种原因 /wp-admin/ 路径会导致重定向循环,但 /wp-admin/index.php 不会。 As such, we can use .htaccess to redirect the /wp-admin/ path to /wp-admin/index.php by adding the following line to your .htaccess file after "RewriteBase /" line like this:因此,我们可以使用 .htaccess 将 /wp-admin/ 路径重定向到 /wp-admin/index.php,方法是将以下行添加到 .htaccess 文件中的“RewriteBase /”行之后,如下所示:

RewriteBase /
RewriteRule  /wp-admin/ /wp-admin/index\.php [L,P]

It worked for me like that.它像那样对我有用。 You final .htaccess would probably look like this:你最终的 .htaccess 可能看起来像这样:

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

Checking the permissions of wp-login.php revealed that they too had somehow been set to 664 - the same permissions that caused index.php to fail and caused the 500 server error.检查wp-login.php的权限发现它们也以某种方式设置为 664 - 导致index.php失败并导致 500 服务器错误的相同权限。

I changed the permissions of wp-login.php to 644 and hey presto, the WordPress login page showed up.我将wp-login.php的权限更改为 644,嘿嘿,WordPress 登录页面出现了。

But on logging in, another redirect loop.但是在登录时,另一个重定向循环。 So, once again, looking at /wp-admin/index.php , the permissions were 664 rather than 644.因此,再次查看/wp-admin/index.php ,权限是 664 而不是 644。

Fixing them led to problems with the next files in line - the dashboard was a right mess.修复它们会导致下一个文件出现问题 - 仪表板一团糟。 One by one, changing from 664 to 644 corrected the issues (/wp-admin/load-scripts.php, /wp-admin/load-styles.php).从 664 改为 644 一一修正了问题(/wp-admin/load-scripts.php、/wp-admin/load-styles.php)。

So it became obvious that a recursive change of permissions was the only way to sort things out.因此很明显,权限的递归更改是解决问题的唯一方法。

My UNIX isn't exactly top notch, but this appears to have worked (running from Mac OS X Terminal).我的 UNIX 并不是一流的,但这似乎有效(从 Mac OS X 终端运行)。 I ran it from the root directory of this WP install.我从这个 WP 安装的根目录运行它。

find . -type f -perm 664 -print -exec chmod 644 {} \;

There might be a better command, but I understand this to mean "find all files with 664 permissions and change them to 644".可能有更好的命令,但我理解这意味着“找到所有具有 664 权限的文件并将它们更改为 644”。

It has fixed my problem.它解决了我的问题。

If you're using Cloudflare you might want to try adding this to the TOP of your wp-config.php file:如果您使用 Cloudflare,您可能想尝试将其添加到 wp-config.php 文件的顶部:

define('WP_SITEURL', 'https://www.example.com');
define('WP_HOME', 'https://www.example.com');
define('FORCE_SSL_ADMIN', true);
define('FORCE_SSL_LOGIN', true);
if(isset($_SERVER['HTTP_CF_VISITOR']) && strpos($_SERVER['HTTP_CF_VISITOR'], 'https')){
  $_SERVER['HTTPS']='on';
}

It's important that you add it to the top of the wp-config.php file or you'll end up with "Sorry, you are not allowed to access this page" error messages.将它添加到 wp-config.php 文件的顶部很重要,否则最终会出现“对不起,您不能访问此页面”错误消息。

Credit: https://www.meltajon.com/dev/wordpress-wp-admin-redirect-loop-with-cloudflare-ssl信用: https : //www.meltajon.com/dev/wordpress-wp-admin-redirect-loop-with-cloudflare-ssl

if your webserver is nginx,you may need check the configure file of your nginx.如果您的网络服务器是 nginx,您可能需要检查您的 nginx 的配置文件。 If there is如果有

if (!-f $request_filename){
    rewrite ^/(.+)$ /index.php?$1& last;
}

Replace these lines with将这些行替换为

try_files $uri $uri/ /index.php?$args;

See also Nginx Pitfalls , WordPress wiki page on nginx另请参阅Nginx 陷阱nginx 上的 WordPress wiki 页面

with nginx config I had originally only this line and experienced the same redirect issue:使用 nginx 配置时,我最初只有这一行并遇到了相同的重定向问题:

location / {
    try_files   $uri /index.php$is_args$args;
}

after adding this everything was fine:添加后一切都很好:

location /wp-admin/ {
    index index.php;
    try_files $uri $uri/ /index.php$args;
}

If you are useing Cloudflare, from SSL/TLS tab of your Cloudflare account, select Full encryption.如果您使用 Cloudflare,请从 Cloudflare 帐户的 SSL/TLS 选项卡中选择完全加密。 It will solve the issue.它将解决问题。 SSL/TLS 设置

I just had to flush my redirects.我只需要刷新我的重定向。 Since I couldn't access the Admin I added this to the top of my functions.php file:由于我无法访问管理员,我将其添加到我的 functions.php 文件的顶部:

flush_rewrite_rules(); exit;

Saved it and refreshed my site.保存并刷新了我的网站。 Then remove the code from your functions.php file and then refresh again.然后从您的functions.php 文件中删除代码,然后再次刷新。 That did it for me.那是为我做的。

I also think it might be a good measure to resave your permalinks.我也认为重新保存您的永久链接可能是一个很好的措施。

PS.附注。 I think the main issue came from theme-my-login as it was redirecting to /login.我认为主要问题来自 theme-my-login,因为它重定向到 /login。

I was getting DoS pages when trying to publish in my WP site.尝试在我的 WP 站点中发布时,我收到了 DoS 页面。 I found advice that changing permissions in the function.php file to 600 could solve the issue, also to add to that file a script snippet .我发现将 function.php 文件中的权限更改为 600 可以解决该问题的建议,还可以向该文件添加一个脚本片段。 It was a WP help page.这是一个WP帮助页面。 I was able to get to the publishing in a work-around way.我能够以一种变通的方式进行出版。 Still have the DoS when I try to open the editor.当我尝试打开编辑器时仍然有 DoS。

To remove the lines删除线条

define('DOMAIN_CURRENT_SITE', 'www.sitename.de');

define('SITE_ID_CURRENT_SITE', 1);
define('BLOG_ID_CURRENT_SITE', 1);

from wp-config.php should do the job.wp-config.php应该可以完成这项工作。

These lines are not necessary for a multi这些行对于多线程不是必需的

In the sites-enabled folder you will need to edit the configuration for your site and add the multisite redirection rules.在启用站点的文件夹中,您需要编辑站点的配置并添加多站点重定向规则。 For Ubuntu 14.04 you will be able to find the path under /etc/nginx/sites-available对于 Ubuntu 14.04,您将能够在 /etc/nginx/sites-available 下找到路径

Add the following block in your server block and you should be able to avoid the infinite redirection loop.在您的服务器块中添加以下块,您应该能够避免无限重定向循环。

#Rewrite multisite '.../wp-.*' and '.../*.php'.
if (!-e $request_filename) {
    rewrite /wp-admin$ $scheme://$host$uri/ permanent;
    rewrite ^/[_0-9a-zA-Z-]+(/wp-.*) $1 last;
    rewrite ^/[_0-9a-zA-Z-]+(/.*\.php)$ $1 last;
}

I had a similar issue in my case it was due to restoring a db script that was created with WP Migrate DB.在我的情况下,我遇到了类似的问题,这是由于恢复了使用 WP Migrate DB 创建的数据库脚本。 The script had merge tags in like "## DEV URL ##" which i needed to fix before running the script on mysql and pointing the wp-config.php to the correct database.该脚本具有像“## DEV URL ##”这样的合并标签,我需要在 mysql 上运行脚本并将 wp-config.php 指向正确的数据库之前修复它。

In my case it was Apache's DirectoryIndex issue.就我而言,这是 Apache 的DirectoryIndex问题。 The wp-admin was being accessed by wp-admin/index.php but not with wp-admin and showing ERR_TOO_MANY_REDIRECTS .wp-admin正在被访问wp-admin/index.php ,但不与wp-admin和显示ERR_TOO_MANY_REDIRECTS

It sounds like Apache's DirectoryIndex may be set "incorrectly".听起来 Apache 的DirectoryIndex可能设置为“不正确”。 Try resetting this at the top of your .htaccess file:尝试在.htaccess文件的顶部重置它:

DirectoryIndex index.php

See the full answer here.在此处查看完整答案。 Can't access admin dashboard with wp-admin without /index.php after it在没有 /index.php 之后,无法使用 wp-admin 访问管理仪表板

My problem was that the hardisk was full.我的问题是硬盘已满。 Trying to log into the wordpress administration panel was redirecting me to wp-login.php.尝试登录 wordpress 管理面板将我重定向到 wp-login.php。 I was able to log in again the moment I deleted some files.当我删除一些文件时,我能够再次登录。

If you have nginx, then also check your index config.如果你有 nginx,那么还要检查你的索引配置。 As for me I had an issue: I've set the following:至于我,我遇到了一个问题:我设置了以下内容:

server {
    server_name _;
    root /var/www/html;
    index /index.php;
}

So as you see I've set index.php with trailing slash, which means that all rewrite requests will go to the index.php in document_root.所以如你所见,我已经用斜杠设置了 index.php,这意味着所有重写请求都将转到 document_root 中的 index.php。 For WP it's wrong, because wp-admin directory has its own index.php对于 WP 来说是错误的,因为 wp-admin 目录有自己的 index.php

The above answers got me pretty close.上面的答案让我非常接近。 In our particular case, someone at some point had added in some rules to the htaccess file in the site root and in the admin folder to block traffic from everywhere except some whitelisted IPs (when attempting to access wp-admin).在我们的特定情况下,有人在某个时候向站点根目录和 admin 文件夹中的 htaccess 文件添加了一些规则,以阻止来自除一些白名单 IP 之外的任何地方的流量(尝试访问 wp-admin 时)。

Example:例子:

<Files wp-login.php>
   order deny,allow
   Deny from all

   # Allow from this IP address
  allow from 123.45.67.89
</Files>

Adding our IP to the whitelist in both files remedied the problem.将我们的 IP 添加到两个文件中的白名单可以解决问题。

I faced same problem after I restore backup from other server , it was promising issue I solve it this way .从其他服务器恢复备份后,我遇到了同样的问题,我以这种方式解决了这个问题。

  chown -R www-data:www-data          /var/www
  chmod -R g+rwx                     /var/www

Where /var/www the place to store website files , replace it with suitable path according to your configuration , eg /usr/share/nginx/www << default Nginx其中/var/www是存放网站文件的地方,根据你的配置替换成合适的路径,例如/usr/share/nginx/www << default Nginx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM