简体   繁体   English

子文件夹中的 Wordpress /wp-admin 重定向问题

[英]Wordpress in subfolder /wp-admin redirect issue

A Wordpress website is installed in a subfolder, let's call it my_site一个 Wordpress 网站安装在一个子文件夹中,我们称之为my_site

I need the website to load subfolder contents when the domain name is accessed (let's say it's https://example.com ), and thus, I have set up my .htaccess file like so:我需要网站在访问域名时加载子文件夹内容(假设它是https://example.com ),因此,我设置了我的.htaccess文件,如下所示:

RewriteEngine on 
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteCond %{REQUEST_URI} !^/my_site/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /my_site/$1 
RewriteCond %{HTTP_HOST} ^(www.)?example.com$ 
RewriteRule ^(/)?$ my_site/index.php [L]

Now, in terms of content and the website overall - everything works correctly.现在,就内容和网站整体而言 - 一切正常。 The issue is with trying to login into the WP dashboard by going directly to https://example.com/wp-admin问题在于尝试通过直接转到https://example.com/wp-admin登录 WP 仪表板

Browser does load the standard WP login screen but upon entering my credentials, the same login form shows up - it's like I simply refreshed the page.浏览器确实加载了标准的 WP 登录屏幕,但在输入我的凭据时,会显示相同的登录表单 - 就像我只是刷新了页面。

Both upon first going to the https://example.com/wp-admin URL and after trying to login, when I experience the "browser refresh-like" behavior, the URL string in browser is set automatically to:在第一次访问https://example.com/wp-admin URL 和尝试登录后,当我遇到“类似浏览器刷新”的行为时,浏览器中的 URL 字符串会自动设置为:

https://example.com/wp-login.php?redirect_to=https%3A%2F%2Fexample.com%2Fmy_site%2Fwp-admin%2F&reauth=1

Same URL decoded:相同的 URL 解码:

https://example.com/wp-login.php?redirect_to=https://example.com/my_site/wp-admin/&reauth=1

So clearly the problem is that my_site is appended inside the redirect_to parameter, but I have no idea how to get rid of it.很明显,问题是my_site附加在redirect_to参数中,但我不知道如何摆脱它。

Any help is greatly appreciated!任何帮助是极大的赞赏!

PS The WP_HOME and WP_SITEURL variables are set in wp-config.php like so (to target both http and https): PS WP_HOMEWP_SITEURL变量在wp-config.php中设置如下(针对 http 和 https):

$hostname = isset( $_SERVER['HTTPS'] ) && strtolower( $_SERVER['HTTPS'] ) == 'on' ? 'https' : 'http';
$hostname .= '://' . $_SERVER['HTTP_HOST'];
define( 'WP_HOME', $hostname );
define( 'WP_SITEURL', $hostname );

Hey all you need to remove (www.)?嘿所有你需要删除(www.)? from RewriteCond like so从 RewriteCond 像这样

RewriteEngine on 
RewriteCond %{HTTP_HOST} ^example.com$
RewriteCond %{REQUEST_URI} !^/my_site/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /my_site/$1 
RewriteCond %{HTTP_HOST} ^example.com$ 
RewriteRule ^(/)?$ my_site/index.php [L]

second, if you decode your URL via URL Decoder第二,如果你通过URL Decoder解码你的 URL

https://example.com/wp-login.php?redirect_to=https%3A%2F%2Fexample.com%2Fmy_site%2Fwp-admin%2F&reauth=1

you will notice my_site which is the root cause that does not allowing to redirect to wp dashboard because in htaccess you restrict to example.com .您会注意到my_site这是不允许重定向到 wp 仪表板的根本原因,因为在 htaccess 中您限制为example.com

Once you remove my_site%2F from URL and re-submit login form you will definitely redirect to dashboard.从 URL 中删除my_site%2F并重新提交登录表单后,您肯定会重定向到仪表板。

Now all you need to config redirect URL to wp-admin such that it does not contain actual wordpress folder现在您只需要将重定向 URL 配置为 wp-admin,使其不包含实际的 wordpress 文件夹

i had the same problem.我有同样的问题。 You probabably have changed to https?您可能已更改为https? the solution is in the database.解决方案在数据库中。

wordpress official site wordpress 官方网站

In some situations, your blog can be seen from inside your domain, but not outside.在某些情况下,您的博客可以从您的域内部看到,但不能从外部看到。 Following the instruction above about changing the wp-options MySQL table might still result in login failure.按照上面有关更改 wp-options MySQL 表的说明操作可能仍会导致登录失败。

In this event, double-check your wp-options table siteurl (WordPress address URL) and home (Blog Address URL) values to make sure they reference the same base externally available address;在这种情况下,请仔细检查您的 wp-options 表 siteurl(WordPress 地址 URL)和 home(博客地址 URL)值,以确保它们引用相同的基本外部可用地址; ie, http://blog.yourdomain.com .即, http://blog.yourdomain.com The standard install may set them to your local (internal) host name, such as http://servername标准安装可能会将它们设置为您的本地(内部)主机名,例如http://servername

Another issue may be if you are redirecting using .htaccess from a non-www url prefix to a www while you have the wp-options table siteurl (WordPress address URL) and home (Blog Address URL) set with non-www prefix.另一个问题可能是,如果您使用 .htaccess 从非 www url 前缀重定向到 www,而 wp-options 表 siteurl(WordPress 地址 URL)和 home(博客地址 URL)设置为非 www 前缀。 Consequently this would create an endless loop which you need to avoid.因此,这将创建一个您需要避免的无限循环。 One way is to disable the .htaccess redirection temporarily by placing # before the line or eliminating the entries entirely and trying to Login again.一种方法是暂时禁用 .htaccess 重定向,方法是在行前放置 # 或完全删除条目并再次尝试登录。 Advanced users may want to adjust the wp-options table siteurl (WordPress address URL) and home (Blog Address URL) through the database.高级用户可能想通过数据库调整wp-options表siteurl(WordPress地址URL)和home(博客地址URL)。 Notice that this issue can also occur if you are redirecting from www to non-www but have your wp-options table siteurl (WordPress address URL) and home (Blog Address URL) set with a www url prefix.请注意,如果您从 www 重定向到非 www,但将 wp-options 表 siteurl(WordPress 地址 URL)和 home(博客地址 URL)设置为 www url 前缀,也会发生此问题。

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

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