php - WordPress 登录重定向不适用于 Nginx 根目录
问题描述
我有一个 wordpress 网站,它将我重定向到请求登录的上一页。它在 apache Web 服务器上运行良好,并可在http://localhost/wp上访问,当我从 apache 移动到 nginx 时,它在 nginx 子目录(/var/www/html/wp)中也可以正常运行,即http://localhost /wp。但是当我在 nginx 根目录(即 /var/www/html/)上部署站点时,登录重定向停止工作并停留在登录页面上。有人可以识别我在配置或重定向代码中做错了什么。
子目录工作正常:
http://localhost/wp/gallery ----> http://localhost/wp-login.php ----> 重定向到 ---> http://localhost/wp/gallery
从根目录:
我想要的是
http://localhost/gallery ----> http://localhost/wp-login.php ----> 重定向到 ---> http://localhost/gallery
它能做什么
http://localhost/gallery ----> http://localhost/wp-login.php ----> 重定向到---> http://localhost/wp-login.php
在此处重定向功能代码:
session_start();
if(wp_get_referer() != get_site_url()."/wp-login.php"){
$_SESSION['back_log'] = wp_get_referer();
}
function admin_default_page() {
$back_log = "";
if(isset($_SESSION['back_log']) && !empty($_SESSION['back_log'])) {
$back_log = $_SESSION['back_log'];
return $back_log;
}
}
add_filter('login_redirect', 'admin_default_page');
给出了构形
server {
listen 80;
server_name localhost;
client_max_body_size 64M;
#proxy_max_temp_file_size 0;
#proxy_buffers 16 16k;
#proxy_buffer_size 16k;
root html/;
index index.php index.html index.htm;
location = /favicon.ico { log_not_found off; access_log off; }
location = /robots.txt { log_not_found off; access_log off; allow all; }
location ~* \.(css|gif|ico|jpeg|jpg|js|png)$ {
expires max;
log_not_found off;
}
location / {
try_files $uri $uri/ /index.php$is_args$args ;
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass 127.0.0.1:9999;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
location /wp {
root html/wp;
try_files $uri $uri/ /wp/index.php$is_args$args;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9999;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
解决方案
推荐阅读
- php - 如何使用 ?在网址中?
- android - Android Studio 在更新 4.0.1 后不工作
- javascript - Chrome 扩展:在 Angular 站点中准备好 DOM 后,无法获取 DOM 元素
- python - 无法使用视图名称“usermodel-detail”解析超链接关系的 URL
- python-3.x - Python 3 Imaplib -(错误:EXPUNGE 失败,BAD [b'Command Argument Error.11'])无法从 Microsoft 服务帐户中删除邮件
- parsing - 斯坦福解析器 - amod 和 nsubj 依赖关系 - 谓词和定语形容词的组合
- java - 在流上调用 forEach 会导致 java.lang.IllegalStateException
- oxid - Phpstan Class_parent 未找到
- excel - Excel合并单元格,排除空值,正确读取日期
- python - 画布项目 event_generate