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

    i would like to 301 redirect old URLs from a site that has been ported over to MODx.

    the problem seems to be an "?" in the old site’s URL

    http://www.domain.com/?open=praxis
    to
    http://www.domain.com/praxis.html

    this doesn’t work:
    RewriteRule ?open=praxis praxis.html [L,NE,R=301]


    without the "?" does:
    RewriteRule open=praxis praxis.html [L,NE,R=301]


    does anyone know how i can get this working?

    ( i placed the rule just below RewriteBase / )

    thanks, j
      • 16278
      • 928 Posts
      ?open=praxis is a query string, not a URL, so you need a rewrite rule using a condition that tests for it. That’s about as far as I dare go in giving .htaccess advice. Following is the closest I found to your situation with a quick burst of googling: http://discuss.joyent.com/viewtopic.php?id=16947. That should set you off on the right track, I hope.
      wink KP
        • 26931
        • 2,314 Posts
        hehe, okay ... at least it’s a part of the URL wink

        thanks KP, i’ll check your link! j
          • 26931
          • 2,314 Posts
          hmmm ... made a Snippet with the following code and placed it on the site start (home page):
          <?php
          $home='1';
          $news='12';
          $kontakt='7';
          switch($_GET['open']) {
          	case 'home' :
          	$modx->sendRedirect($modx->makeUrl($home), 0, 'REDIRECT_HEADER', 'HTTP/1.1 301 Moved Permanently');
          	break; 
          	case 'aktuelles' :
          	$modx->sendRedirect($modx->makeUrl($news), 0, 'REDIRECT_HEADER', 'HTTP/1.1 301 Moved Permanently');
          	break; 
          	case 'kontakt' :
          	$modx->sendRedirect($modx->makeUrl($kontakt), 0, 'REDIRECT_HEADER', 'HTTP/1.1 301 Moved Permanently');
          	break; 
          	}
          ?>
          ..it’s working, but is this legit? anything i should change? is it secure? smiley

          thanks, j
            • 26931
            • 2,314 Posts
            guess this is a better way to handle it ... found it here: http://modxcms.com/forums/index.php/topic,45869.msg270970.html#msg270970

            <?php
            // old URl with the corresponding new ID
            $urlid = array(
            	'home' => '1',
            	'praxis' => '3',
            	'kontakt' => '7',
            	'impressum' => '8'
            	);
            
            // set default
            $url= '1';
            
            if (isset($_GET['open']) && isset($urlid[$_GET['open']])) {
            	$url = $urlid[$_GET['open']];
            	$modx->sendRedirect($modx->makeUrl($url), 0, 'REDIRECT_HEADER', 'HTTP/1.1 301 Moved Permanently');
            	}
            ?>