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

    I have another non-modx-related question about SEO.

    I wan’t to change:
    http://www.DOMAIN.nl/popup.php?pid=123&id=12
    to
    http://www.DOMAIN.nl/index.php?pid=123&id=12

    using .htaccess is this posibible? if yes do you have an example mod_rewrite code or something? (ps; PHP redirects are not an option)

    I know this is not fully SEF but it’s needed because people aren’t supposed to land on popup.php (at least not via search engines).

    Looking forward too hear some suggestions smiley

    /m
      Quality doesn't need a big signature.
      • 19534
      • 183 Posts
      you may do this by writing some rewrite rules in your .htacces file (if using apache)
        Add-On to easily manage your multilingual sites: Babel
      • Untested.

        RewriteRule ^popup.php?(.*)$ index.php?$1 [NC]
          Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

          Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
          • 18940
          • 152 Posts
          Hi Mark,

          Your RewriteRule was correct, however now I know this is not what I want, I’m going to try if I can keep popup.php out of search engines using canonical urls and other META tags smiley

          Thnx guys!
            Quality doesn't need a big signature.
            • 18940
            • 152 Posts
            As said above RewriteRules aren’t working for me so I used the following META tags, canonical URL (with a script) and robots.txt. The page will still be visible but Search Engines should ignore (most of) it:

            Basic meta tags:
            	<!--  HIDE POPUP.PHP FROM SEARCH ENGINES -->
            	<meta name="robots" content="noindex, follow" /> <!-- Spiders will ignore this page but will crawl all other website pages -->
            	<meta name="robots" content="noarchive" /> <!-- Remove archived pages -->
            	<meta name="googlebot" content="nosnippet" /> <!-- Prevent Google from displaying snippets  -->
            


            canonical URL with script too shorten http://www.abc.xx/popup.php?id=123&pid=12 to http://www.abc.xx/index.php?id=123&pid=12
            	<?php
            		function selfURL() { //Get full URL
            			$s = empty($_SERVER["HTTPS"]) ? ''
            				: ($_SERVER["HTTPS"] == "on") ? "s"
            				: "";
            			$protocol = strleft(strtolower($_SERVER["SERVER_PROTOCOL"]), "/").$s;
            			$port = ($_SERVER["SERVER_PORT"] == "80") ? ""
            				: (":".$_SERVER["SERVER_PORT"]);
            			return $protocol."://".$_SERVER['SERVER_NAME'].$port.$_SERVER['REQUEST_URI'];
            		}
            		function strleft($s1, $s2) { //Strip full URL
            			return substr($s1, 0, strpos($s1, $s2));
            		}
            
            		function cleanURL($url = '')
            		{ //Shorten full URL
            			$matchHTTP	= substr($url, 0, 27);
            			$matchWWW	= substr($url, 0, 20);
            			$matchHTTPS	= substr($url, 0, 28);
            
            			if ($matchHTTP=='http://www.abc.xx/popup.php')
            			{
            				$url= 'http://www.abc.xx/index.php'.substr($url, 27);
            			}
            			elseif ($matchHTTPS=='https://www.abc.xx/popup.php')
            			{
            				$url= 'https://www.abc.xx/index.php'.substr($url, 28);
            			}
            			elseif ($matchWWW=='www.abc.xx/popup.php')
            			{
            				$url= 'http://www.abc.xx/index.php'.substr($url, 20);
            			}
            			else
            			{
            				$url = '';
            			}
            			return $url;
            		}
            
            		$fullURL = (selfURL());
            	?><link rel="canonical" href="<?php echo cleanURL($fullURL); ?>" />
            


            robots.txt:
            Disallow: /popup.php


            Note: the script above works well but should be improved before use! For me this was a not-so-quick-but-dirty solution smiley
              Quality doesn&#39;t need a big signature.