We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 4095
    • 372 Posts
    Is there any one to change the extension of a single link when using friendly URLS and add extensins?

    I have one link I want to end in XML. I tried to give it an alias of .XML but it added .HTML to the end of it so it now reads DOCUMENT.XML.HTML

      [img]http://www.emanz.ac.nz/assets/images/logo/emanz-icon_16x16.gif[/img] Emergency Management Academy of New Zealand [br] http://www.emanz.ac.nz[br][br]MODx Sandbox Login: sandbox Password: castle [br]
      Admin Sandbox Login: sandbox Password: castle
      • 32963
      • 1,732 Posts
      Here’s a quick fix for $modx->makeUrl to not appy .html suffix to aliases with an extension (e.g. .xml, .pdf, etc)

      I have not tested it but I think it should work.

      	function makeUrl($id, $alias='', $args='') {
      		$url= '';
      		$virtualDir= '';
      		if(!is_numeric($id)) {
      			$this->messageQuit('`'.$id.'` is not numeric and may not be passed to makeUrl()');
      		}
      		if($args!='' && $this->config['friendly_urls']==1) {
      			// add ? to $args if missing
      			$c = substr($args,0,1);
      			if ($c=='&') $args = '?'.substr($args,1);
      			elseif ($c!='?') $args = '?'.$args; 
      		}
      		elseif($args!='') {
      			// add & to $args if missing
      			$c = substr($args,0,1);
      			if ($c=='?') $args = '&'.substr($args,1);
      			elseif ($c!='&') $args = '&'.$args; 
      		}
      		if($this->config['friendly_urls']==1) {
      			if($alias!='') {
      				$url= $this->config['friendly_url_prefix'].$alias;
      			} elseif($alias=='') {
      				$alias = $id;
      				if($this->config['friendly_alias_urls']==1) {
      					$al = $this->aliasListing[$id];
      					$alPath = !empty($al['path'])? $al['path'] . '/': '';
      					if($al && $al['alias']) $alias = $al['alias'];
      				}
      				$alias = $alPath . $this->config['friendly_url_prefix'].$alias.$suffix;
      				$url = $alias;
      			}			
      			$pa = pathinfo($url); // get path info array
      			$suffix = !empty($pa[extension]) ? '':$this->config['friendly_url_suffix'];
      			$url.= $suffix.$args; // apply suffix and arguments
      		}
      		else {
      			$url= 'index.php?id='.$id.$args;
      		}
      		return $this->config['base_url'] . $virtualDir . $url;
      	}
        xWisdom
        www.xwisdomhtml.com
        The fear of the Lord is the beginning of wisdom:
        MODx Co-Founder - Create and do more with less.
        • 4095
        • 372 Posts
        I replaced the original code in document.parser.class.inc.php with the one above, but it doesn’t seem to work. Still appending .html

        Any other ideas as this is way over my head?

        [EDIT] When I compare what was in the original file and the code above, they are the same.... did you cut n paste the wrong bit?
          [img]http://www.emanz.ac.nz/assets/images/logo/emanz-icon_16x16.gif[/img] Emergency Management Academy of New Zealand [br] http://www.emanz.ac.nz[br][br]MODx Sandbox Login: sandbox Password: castle [br]
          Admin Sandbox Login: sandbox Password: castle
          • 32963
          • 1,732 Posts
          Hmmm,

          That’s odd they can’t be the same.

          See here:

          		if($this->config['friendly_urls']==1) {
          			if($alias!='') {
          				$url= $this->config['friendly_url_prefix'].$alias;
          			} elseif($alias=='') {
          				$alias = $id;
          				if($this->config['friendly_alias_urls']==1) {
          					$al = $this->aliasListing[$id];
          					$alPath = !empty($al['path'])? $al['path'] . '/': '';
          					if($al && $al['alias']) $alias = $al['alias'];
          				}
          				$alias = $alPath . $this->config['friendly_url_prefix'].$alias.$suffix;
          				$url = $alias;
          			}			
          			$pa = pathinfo($url); // get path info array
          			$suffix = !empty($pa[extension]) ? '':$this->config['friendly_url_suffix'];
          			$url.= $suffix.$args; // apply suffix and arguments
          		}
          		else {
          			$url= 'index.php?id='.$id.$args;
          		}
          
            xWisdom
            www.xwisdomhtml.com
            The fear of the Lord is the beginning of wisdom:
            MODx Co-Founder - Create and do more with less.
            • 4095
            • 372 Posts
            Must have screwed up my copy and paste as I used Winmerge to compare files and it said they were the same. However re done it with my own eyes, and yup they are different... sorry smiley

            This however didn’t seem to make a difference, the link still has .html appended, so it now has rssfeed.xml.html even though the alias in rssfeed.xml. If I change the alias it, the new one still has .html appended

            If I type in the url http://www.emanz.ac.nz/rssfeed.xml, I get the document, I also get it if I add .html to that.
              [img]http://www.emanz.ac.nz/assets/images/logo/emanz-icon_16x16.gif[/img] Emergency Management Academy of New Zealand [br] http://www.emanz.ac.nz[br][br]MODx Sandbox Login: sandbox Password: castle [br]
              Admin Sandbox Login: sandbox Password: castle
              • 8382
              • 253 Posts
              I have troubled with the same problem, too.
              I show my solution.

              As well as the mod mentioned above, I add the followings.

              in document.parser.class.inc.php
              	function makeFriendlyURL($pre,$suff,$alias) {
              		// Modified for .xml extension 2006/1/18
              		$dir = dirname($alias);
              		$painfo = pathinfo($alias);
              		$tmpsuffix = !empty($painfo[extension]) ? '':$suff;
              		return ($dir!='.' ? "$dir/":"").$pre.basename($alias).$tmpsuffix;
              //		return ($dir!='.' ? "$dir/":"").$pre.basename($alias).$suff;
              	}
              

              And, for Export, in export_site.static.action.php
              //		$filename = !empty($alias) ? $prefix.$alias.$suffix : $prefix.$id.$suffix ;
              		if(empty($alias)) {
              			$filename = $prefix.$id.$suffix;
              		}
              		else {
              			$painfo = pathinfo($alias);
              			$tmpsuffix = !empty($painfo[extension]) ? '':$suffix;
              			$filename = $prefix.$alias.$tmpsuffix;
              		}
              


              It seems to be working properly. wink