We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 25969
    • 118 Posts
    Hi guys,

    I’m having a little mod_rewrite trouble trying to remove "default.asp" from requests which include it in the URL to the new MODx website, due to 100s of existing backlinks. For example -
    #New with MODx
    http://www.domain.com/ 
    http://www.domain.com/about/
    http://www.domain.com/about/contact/
    
    #Old with ASP, currently 404-ing
    http://www.domain.com/default.asp
    http://www.domain.com/about/default.asp
    http://www.domain.com/about/contact/default.asp

    The sitemap is exactly like the old website’s so removing "default.asp" across the board should do the trick, however I’m unsure where and how this should be done in the.htaccess file in addition to the MODx FURL rules. Any tips?
      • 25969
      • 118 Posts
      I sorted it, just made a plugin (System Event: OnPageNotFound) to strip default.asp if it exists in the URI.

      $needle = "default.asp";
      
      if (strstr($modx->documentIdentifier, $needle)) {
      	$redirectURL = 'http://' . $_SERVER['HTTP_HOST'] . str_replace($needle, '', $_SERVER['REQUEST_URI']);
      	$modx->sendRedirect($redirectURL, 0, 'REDIRECT_HEADER', 'HTTP/1.1 301 Moved Permanently');
      }