Gist 8996e99323835c6726c458f94a895281
✓ Published0🌍 Public
KKopylovVitalik
Last edited Apr 7, 2020
Created on Apr 7, 2020
This example demonstrates a WordPress redirect system that forces all incoming URLs to lowercase. It shows how a site can enforce consistent URL casing by intercepting requests before page rendering. The code uses the `template_redirect` action hook to check whether the requested URI differs from its lowercase version, and if so, issues a 301 redirect using PHP’s `header()` function. The redirect constructs the new location by combining the site’s home URL, the `HTTPS_HOST` server variable, and the lowercased request URI. This approach ensures search engines and users are permanently directed to canonical lowercase paths, preventing duplicate content issues.
AI-generated description