You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

迁移服务器后WordPress报REQUEST_URI未定义,无法访问wp-admin

Fixing "Undefined constant REQUEST_URI" Error in WordPress After Server Migration

Hey there, let's tackle this REQUEST_URI error you're facing. Since you've already ruled out themes and plugins by swapping them out and disabling all plugins, the issue is almost certainly tied to your new server's configuration—here are the targeted fixes you can try:

1. Check Your Server Type (Apache vs. Nginx)

This error is super common when migrating from Apache to Nginx, because Nginx doesn't pass the REQUEST_URI environment variable to PHP by default.

If you're using Nginx:

Add the fastcgi_param REQUEST_URI $request_uri; line to your site's Nginx configuration file, inside the location ~ \.php$ block. Here's what the updated block should look like:

location ~ \.php$ {
    fastcgi_pass unix:/run/php/php7.4-fpm.sock; # Adjust this path to match your PHP-FPM socket
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param REQUEST_URI $request_uri; # This line is critical
    include fastcgi_params;
}

After adding this, restart Nginx with sudo systemctl restart nginx (or your server's equivalent restart command).

2. Adjust PHP Configuration

If you're using Apache and still seeing the error, the problem might be with how PHP is handling environment variables:

  • Open your php.ini file (location varies by server—common paths are /etc/php/7.4/apache2/php.ini or /usr/local/php/php.ini).
  • Look for the variables_order directive. If it's set to variables_order = "GPCS", change it to variables_order = "EGPCS" (the E stands for environment variables).
  • Restart your Apache server or PHP-FPM service to apply the change.

Temporary Emergency Fix:

If you need a quick workaround while sorting out server configs, add this code to the top of your WordPress wp-config.php file (before any other WordPress-specific code):

// Manually define REQUEST_URI if it's missing
if (!isset($_SERVER['REQUEST_URI'])) {
    $_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'] . (!empty($_SERVER['QUERY_STRING']) ? '?' . $_SERVER['QUERY_STRING'] : '');
}

Note: This is a band-aid—always fix the root server config issue long-term.

3. Verify .htaccess and Apache Modules

For Apache servers:

  • Make sure your WordPress .htaccess file has the default rewrite rules (if you haven't customized it):
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
  • Confirm that the mod_rewrite module is enabled. Run sudo a2enmod rewrite to enable it, then restart Apache with sudo systemctl restart apache2.

One of these steps should resolve the undefined REQUEST_URI error—start with checking your server type since that's the most frequent culprit when moving to a new server. Let me know if you need help with any specific part of these fixes!

内容的提问来源于stack exchange,提问作者user3501194

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 09:42:09