Support » Plugins and Hacks » [Plugin: W3 Total Cache] Stop Redirection Caching

  • 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

    http://wordpress.org/extend/plugins/w3-total-cache/

Viewing 1 replies (of 1 total)
  • Why dont you use .htaccess redirect instead? Its probably something with your code that causes issue. Also can try latest version of the plugin.

Viewing 1 replies (of 1 total)
  • The topic ‘[Plugin: W3 Total Cache] Stop Redirection Caching’ is closed to new replies.