Skip to content

Instantly share code, notes, and snippets.

Created September 5, 2017 00:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/7c1592d763baeb89035e02f7bf1fa41a to your computer and use it in GitHub Desktop.
Save anonymous/7c1592d763baeb89035e02f7bf1fa41a to your computer and use it in GitHub Desktop.
fix wprocket-slash.php
<?php
defined( 'ABSPATH' ) or die( 'Cheatin\' uh?' );
/*
Plugin Name: Enforce Trailing Slash on URLs
Author: Jonathan (WP Rocket Team)
Author URI: http://wp-rocket.me
*/
add_filter( 'before_rocket_htaccess_rules', '__force_trailing_slash' );
function __force_trailing_slash( $marker ) {
$redirection = '# Force trailing slash' . PHP_EOL;
$redirection .= 'RewriteEngine On' . PHP_EOL;
$redirection .= 'RewriteCond %{REQUEST_FILENAME} !-f' . PHP_EOL;
$redirection .= 'RewriteCond %{REQUEST_METHOD} GET' . PHP_EOL;
$redirection .= 'RewriteCond %{REQUEST_URI} !(.*)/$' . PHP_EOL;
$redirection .= 'RewriteRule ^(.*)$ http' . ( is_ssl() ? 's' : '' ) . '://%{HTTP_HOST}/$1/ [L,R=301]' . PHP_EOL . PHP_EOL;
$marker = $redirection . $marker;
return $marker;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment