Menu

SES urls problem

Help
2003-08-07
2003-08-07
  • Gilles Laborderie

    Hi,

    I installed and played with PHX. It's a really neat framework and I like it because it's simple.

    I am having a problem when SES is turned on. When I am looking at http://localhost/phx/phx.articles.read/id/3, my browser ( IE 6 ) interprets all relative links as follow :

    Home -> http://localhost/phx/phx.articles.read/id/phx.index

    News -> http://localhost/phx/phx.articles.read/id/phx.news.index

    Whereas the correct links should be :

    Home -> http://localhost/phx/phx.index

    News -> http://localhost/phx/phx.news.index

    A workaround would to add the following line in the root app_layout.php file :
    <base href="http://localhost/phpx/" />

    Can anyone think of another solution ?

    Gilles

     
    • Abdallah Al Utaibi

      Hi,

      You're putting it in a subdirectory, so check your rewrite statement. Check this web i set as an example:

      http://www.php4a.com with .htacess set to:
      #
      RewriteEngine on
      RewriteRule ^(phx\.[a-z0-9]+)(.*)$  /index.php?phx_c=$1$2 [NC,QSA,L]
      #

      This will redirect all requests to the absolute /index.php. I thought it's better to remove the leading slash, so it can work with subdirectories.

      In http://php4a.com/sub1, the background color of the title should be yellow. But because the subdirectory has the same .htaccess, all requests will go back to the root directory because of the leading slash in the new .htaccess inside /sub1/.

      So, this is a problem! my app located in sub1 will not work!!!

      Check this also: http://php4a.com/sub2 this time I changed its .htaccess file by putting the name of the directory in the .htaccess file, and the result is good.

      This is the .htaccess inside /sub2/, note the path in the rule:
      #
      RewriteEngine on
      RewriteRule ^(phx\.[a-z0-9]+)(.*)$  /sub2/index.php?phx_c=$1$2 [NC,QSA,L]
      #

      Finally, in http://php4a.com/sub3 i changed the .htaccess to try to make it more generic by only removing the leading slash:
      #
      RewriteEngine on
      RewriteRule ^(phx\.[a-z0-9]+)(.*)$  index.php?phx_c=$1$2 [NC,QSA,L]
      #

      The result as you can see is not good.

      So try to put the path of the PHX application subdirectory. I don't know about Apache on windows.

      Please tell me if it works with you.

      Thanks

       
    • Abdallah Al Utaibi

      Well gillesl,

      After all this research, i found out that /sub2/ and /sub3/ may work fine, looks like they are good configuration. I think the problem is with the phx_url API function not formatting the URL correctly. This because it returns the relative path and IE will ofcourse start from the current URL, in this case: /sub2/phx.news.read/id/. So it will add to it: "phx.index" and the result will be "/sub2/phx.news.read/id/phx.index". IE will use the BASE URL in case you provide it, so yes, this will solve the problem.

      But "phx_url" should return the absolute path, so there should be no need for this workaround.

      I will fix it and release a bug-fix release soon (probably version 1.1). This modification is basically to resolve this issue

      I will check it see if the "mod_rewrite" configurations above are correct. However, I'm sure /sub1/ configuration will not work properly since it redirects everything back to the root directory.

      Thanks

       
      • Gilles Laborderie

        Yep, phx_url returns a relative URL and therefore the browser applies it to what he thinks is the current directory but is actually not the correct one.

        I think the 'base' tag approach would be better than having phx_url return an absolute URL because if you do it for URLs, you'll have to do it for image sources also.

        Tell me what you think.

        Gilles

        PS : As for subdirectory, it's not a problem as long as you update the .htaccess rule like you did in sub2.

         
    • Abdallah Al Utaibi

      I think PHX shouldn't return wrong URLs anyway. So, latest release 1.1 will have a new config, $phx["url_base"]. This can be set to empty in the phx_config.php if you still want relative URLs. This is gonna be used only by phx_url function and only if SES is enabled.

      By the way, /sub3/ works fine, so we have now a portable configuration of the .htaccess file, i tried it here: http://php4a.com/sub4, and it's perfect i guess. sub4 is running 1.1 and I just replaced the phx.php file!

      As for IMG sources, No, it will not have any effect! it's totally irrelavent! remember that mod_rewrite only writies URLs that start with "phx.". Please explain to me more if you have something im mind

      Thanks for you comments.

       

Log in to post a comment.

MongoDB Logo MongoDB