WordPress.org

Ready to get started?Download WordPress

Forums

[Plugin: W3 Total Cache] Stop Redirection Caching (2 posts)

  1. sabhandari
    Member
    Posted 1 year ago #

    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/

  2. Frederick Townes
    Member
    Posted 1 year ago #

    Why dont you use .htaccess redirect instead? Its probably something with your code that causes issue. Also can try latest version of the plugin.

Topic Closed

This topic has been closed to new replies.

About this Topic