Hi,
I am trying to perform a 301 redirect when the URL to my web pages doesn't have single slash. For example a URL as http://sample.com// will get 301 redirected to http://sample.com/
I have written the following php code for the same in my header.php file at the top before writing any other headers.
$string = $_SERVER['REQUEST_URI'];
$len = strrpos($string , '/');
$flag = false;
if((strlen($string)-1)!=($len)){
header("HTTP/1.1 301 Moved Permanently");
header("Location: ".$string);
} else {
while($string[$len-1]=='/'){
$string[$len]='';
$len = strrpos($string , '/');
$flag = true;
}
}
if($flag) {
header("HTTP/1.1 301 Moved Permanently");
header("Location: ".$string);
}
When I clear all caches for W3TC, I do get 301 redirect header but after that I am getting 200 OK response. Is W3TC caching the last output of my php code present in header.php.
My URL: http://javaexperience.com