Blog / WordPress/ Fixing WordPress Tag Page 404 Errors After Enabling Permalinks: A System Encoding Guide

Fixing WordPress Tag Page 404 Errors After Enabling Permalinks: A System Encoding Guide

解决WordPress伪静态后标签页404错误:系统编码设置指南

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.

  1. Open the configuration file with a text editor:
    vi /etc/sysconfig/i18n
  2. Find the LANG setting. Its default value might be:
    LANG="en_US.UTF-8"
  3. Change it to Chinese UTF-8 encoding:
    LANG="zh_CN.UTF-8"
  4. Save and exit the editor.
    In vi:
    Press Esc to ensure you are in command mode.
    Type :wq and press Enter to save and quit.
    (The original mentioned q!, which forces quit without saving; :wq or :x is correct here.)
  5. 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_rewrite module is enabled, or that the Nginx site configuration includes the correct WordPress rewrite rules.
  • File Permissions: Check if the .htaccess file (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.

Post a Comment

Your email will not be published. Required fields are marked with *.