Last active
April 20, 2020 13:53
-
-
Save RiodeJaneiroo/96733355700463d089ffb215c7724133 to your computer and use it in GitHub Desktop.
[Wordpress SEO URL few slash/slesh] redirect from multiple sleshes to one #seo #wordpress #redirect #htaccess #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
RewriteCond %{THE_REQUEST} \ (.*)//+ | |
RewriteRule (.*) https://www.kaper.pro/$1 [R=301,L] |
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 | |
add_filter( 'request', 'removeMultipleSlash' ); | |
function removeMultipleSlash( $query_vars ){ | |
$request = urldecode($_SERVER['REQUEST_URI']); | |
$re = '/\/\/+/m'; | |
if( preg_match($re, $request)){ | |
$str = $request; | |
$subst = '/'; | |
$result = preg_replace($re, $subst, $str); | |
wp_safe_redirect( $result, 301); | |
} | |
return $query_vars; | |
} |
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
$request = urldecode($_SERVER['REQUEST_URI']); | |
$re = '/\/\/+/m'; | |
if( preg_match($re, $request)){ | |
$str = $request; | |
$subst = '/'; | |
$result = preg_replace($re, $subst, $str); | |
header("HTTP/1.1 301 Moved Permanently"); | |
header("Location: $result"); | |
exit(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment