Skip to content

Instantly share code, notes, and snippets.

@zacscott
Last active March 11, 2017 11:08
Show Gist options
  • Save zacscott/030a7e4bffcba09feedfd71a2c26470f to your computer and use it in GitHub Desktop.
Save zacscott/030a7e4bffcba09feedfd71a2c26470f to your computer and use it in GitHub Desktop.
Forces all WordPress lowercase URLs
<?php
/**
* Plugin Name: Force Lowercase URLs
* Description: Forces all lowercase URLs
* Version: 1.0
* Author: Zachary Scott
*/
if( ! is_admin() ){
add_action( 'init', 'zs_force_lower_urls' );
}
function zs_force_lower_urls(){
$url = $_SERVER['REQUEST_URI'];
if ( preg_match( '/[\.]/', $url ) ){
return;
}
if ( preg_match( '/[A-Z]/', $url ) ) {
$lc_url = strtolower( $url );
header( "Location: " . $lc_url, true, 301);
exit( 0 );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment