Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.