Created
September 5, 2017 00:01
-
-
Save anonymous/7c1592d763baeb89035e02f7bf1fa41a to your computer and use it in GitHub Desktop.
fix wprocket-slash.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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