Problem Description
After enabling permalinks (pseudo-static URLs) on a WordPress site, clicking on tag archive pages may result in a "404 Page Not Found" error. This often occurs due to a mismatch between the server's system locale/encoding and the website's content encoding, causing issues with URL rewrite rules or path resolution.
Solution: Correct System Locale and Encoding Settings
The core solution is to ensure the server operating system's default locale and character encoding match your website's primary language (e.g., Chinese). For Chinese WordPress sites, it is recommended to set the system encoding to zh_CN.UTF-8.
Steps for Older Linux Systems (CentOS/RHEL 6 and earlier)
For older Linux distributions like CentOS 6, the system locale is typically controlled by the /etc/sysconfig/i18n file.
- Open the configuration file with a text editor:
vi /etc/sysconfig/i18n - Find the
LANGsetting. Its default value might be:LANG="en_US.UTF-8" - Change it to Chinese UTF-8 encoding:
LANG="zh_CN.UTF-8" - Save and exit the editor.
In vi:
PressEscto ensure you are in command mode.
Type:wqand press Enter to save and quit.
(The original mentionedq!, which forces quit without saving;:wqor:xis correct here.) - For the changes to take effect, restart the server or log out and back in. Some settings may require restarting related services (e.g., Apache/Nginx).
For Modern Linux Systems (CentOS/RHEL 7+, Ubuntu 18.04+)
On newer systems, it is recommended to use the localectl command or edit the /etc/locale.conf file.
Method 1: Using localectl (Recommended)
sudo localectl set-locale LANG=zh_CN.UTF-8
This command directly updates the /etc/locale.conf file.
Method 2: Manual Configuration
sudo vi /etc/locale.conf
Ensure the file contains or add the following line:
LANG=zh_CN.UTF-8
After saving, restart the server or log out and back in for the new environment to take effect.
Other Possible Causes and Checks
If the problem persists after adjusting the system encoding, check the following:
- WordPress Permalink Settings: Log into the WordPress admin dashboard, navigate to Settings → Permalinks, and click "Save Changes" to refresh the rewrite rules (.htaccess or Nginx configuration).
- Web Server Configuration: Ensure Apache's
mod_rewritemodule is enabled, or that the Nginx site configuration includes the correct WordPress rewrite rules. - File Permissions: Check if the
.htaccessfile (if using Apache) in the website root directory is writable and contains the correct rules. - Tag Slug: Check if the problematic tag slug contains special characters or spaces. Try changing it to a simple, English-only slug.
Summary
A 404 error on WordPress tag pages with permalinks enabled is often caused by a server system encoding mismatch, a common but easily overlooked issue. Setting the system locale to zh_CN.UTF-8 can resolve path parsing problems due to encoding inconsistencies. Choose the appropriate configuration method based on your Linux system version. After making changes and restarting services, remember to clear both browser and WordPress cache before testing.