We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 32241
    • 1,495 Posts
    Do you know any issue with $modx->sendRedirect()?

    I tried to configure newspublisher to my client’s need, but for some reason I found out that the redirection is working but it will redirect the user to numbered alias, instead of the given alias on newspublisher. I trouble shoot this, and found out that it’s not a problem from $modx->makeUrl(), because the result being generated is including the virtual dir and the alias, instead the sendredirect keep redirecting with a numbered alias such as "http://domain.com/1.html", instead of "http://domain.com/virtualdir/alias.html".

    Could somebody help me with this? I tried to see the code, but I don’t really have a clue of what’s going on with it.

    Thanks
      Wendy Novianto
      [font=Verdana]PT DJAMOER Technology Media
      [font=Verdana]Xituz Media
    • Can you show me the call to sendRedirect() and makeUrl() in your code? I’d be glad to help figure out what’s happening.
        • 32241
        • 1,495 Posts
        Ehmm,

        I checked the makeurl, by calling makeurl, and feeding the function with specific page id, and it shows the full alias with its corresponding virtual dir.

        So I assume that the sendredirect is not sending the redirection to the alias path, instead it will use number, because that’s what happen in my newspubsliher. When I submit a new page, it will redirect the user to pageid.html, instead of virtualdir/pagealias.html.

        I don’t know how to check the sendredirect output regarding about this, but the makeurl works like a charm, it proofs the improvement of makeurl, compare to the 0.9.0 version.

        Thanks
          Wendy Novianto
          [font=Verdana]PT DJAMOER Technology Media
          [font=Verdana]Xituz Media
        • sendRedirect should be taking you to the URL being returned by makeUrl, if that’s how you are calling it. I cannot reproduce the problem you are describing. Any kind of code reference here would help me resolve this for you.
            • 32963
            • 1,732 Posts
            Hi,

            I’ve found another issue with sendRedirect(). The problem is that makeUrl returns the url as /[base_url]/[alias].html

            From what I understand the Location header requires the full url in order to work properly. This means that it requires the htttp:// portion as well

            example:

            // this will fail and cause a 404 error
            header('Location: /[base_url]/[alias].html ');
            
            // this will work
            header('Location: http://domain.com/[base_url]/[alias].html ');


            Tested on IIS 5, Windows XP using WebLogin Snippet

            Here’s the a quick fix:

            Replace line 107 inside the sendRedirect function with:

            // check if url has /$base_url 
            global $base_url,$site_url;
            if (substr($url,0,strlen($base_url))==$base_url) {
            	// append $site_url to make it work with Location:
            	$url = $site_url.substr($url,strlen($base_url));
            }
            $header = 'Location: '.$url;
            


            Please test to confirm.


              xWisdom
              www.xwisdomhtml.com
              The fear of the Lord is the beginning of wisdom:
              MODx Co-Founder - Create and do more with less.
            • Raymond’s fix above has been committed as rev 723.
                Ryan Thrash, MODX Co-Founder
                Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
                • 17665
                • 54 Posts
                Wendy, how will this effect your subsites?

                If there’s a mod we need to make, please let me know as I think this might explain the strange errors we have been getting with FirstChildRedirect (hopefully).

                Thanks!
                  • 32241
                  • 1,495 Posts
                  I think this will affect the subsites hack.
                  I hacked the makeurl api to return the cut down version of base url. If you’re using the right domain, the cut down base url will work just fine, because I also hacked the main parser to append the missing alias in front of the cut down version of base url.

                  Now, if this the sendRedirect using the default MODx installation, basically the hack will assume that every base path has to be returned in the right format, so the cut down version will not work.
                  I’ll see whther this is true or not.

                  Btw, Banzai also having a problem on his site, which I can’t figure out why, can you help me determine what’s the problem with it? I assume if it works on yours and mine, so it’s suppose to work on his.
                    Wendy Novianto
                    [font=Verdana]PT DJAMOER Technology Media
                    [font=Verdana]Xituz Media