Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Nov 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Lightbulb Friendly URL's without mod_rewrite?

    Hi all

    As you know SEF (Search Engine Friendly) URL's are becoming more popular daily. The easiest way make it is .htacces, but it needs mod_rewrite to be enabled on server and it's a big problem for many of host providers.

    Is there any other ways to make friendly URL's?

    Thanks, Otto.

  • #2
    ess
    ess is offline
    Regular Coder
    Join Date
    Oct 2006
    Location
    United Kingdom
    Posts
    866
    Thanks
    7
    Thanked 30 Times in 29 Posts
    Yes of course there is.

    Basically, you need to specify a 404 NOT Found error page. If you are running on Apache....then do the following in a .htaccess file

    Code:
    ErrorDocument 404 /internal_handle/url.php
    Note that we have a folder called "internal_handle" and within that folder...we defined another url.php which would take care of 404 NOT Found errors.

    the following is a sample of how you can handle a NOT FOUND URL in the url.php file.

    PHP Code:
    <?php
        $pages 
    explode("/",$_SERVER['REQUEST_URI']);
        
        echo 
    "<h4>Requested URL Broken Down</h4>";
        
        foreach( 
    $pages as $k => $v ) {
            echo 
    $k ": " $v "<br/>";
        }
    ?>
    <p>
        Go <a href="/">Back</a>
    </p>
    I have also create an index.php file for you to experiment with. all it contains is just a sample of links. here it goes..

    Code:
    <ul>
    <li><a href="/first_page/">first page</a></li>
    <li><a href="/second_page/">second page</a></li>
    <li><a href="/first_page/child_page">first page | child page</a></li>
    <li><a href="/second_page/child_page/">second page | child page</a></li>
    <li><a href="/another page/">another page</a></li>
    </ul>
    Let's know if you need more help.

    cheers,
    ess

  • #3
    Regular Coder
    Join Date
    Mar 2006
    Location
    Nigeria
    Posts
    192
    Thanks
    0
    Thanked 0 Times in 0 Posts
    For more explanation on ess' post, see http://www.zend.com/zend/art/scriptcaching.php

  • #4
    New to the CF scene
    Join Date
    Nov 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hmm... Never hared about it before. Thanks guys

  • #5
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,040
    Thanks
    10
    Thanked 92 Times in 90 Posts
    Alternatively (and not requiring .htaccess at all) you can use the server variable $_SERVER['PATH_INFO'];

    e.g with a url.. http.....blah.com/index.htm/section1/title1

    $_SERVER['PATH_INFO'] will contain `/section1/title1`, explode that
    PHP Code:
    <?php
    $bits 
    explode('/'$_SERVER['PATH_INFO'] );
    print_r($bits);
    ?>
    you can then use $bits[1] and/or $bits[2]/3/4/5 whatever to query your DB or server up the appropriate page.

    This all assumes a standard apache configuration ... try it and see
    Note though that there are issues related to this , with a url of ...index.htm/var1/var2 then paths (for images/links etc) are relative to /index/var1/var2 NOT /index.htm e,g with an 'images' folder at the same level as index.htm you would have to call `../../images/img.jpg` rather than the expected `./images/img.jpg`
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #6
    ess
    ess is offline
    Regular Coder
    Join Date
    Oct 2006
    Location
    United Kingdom
    Posts
    866
    Thanks
    7
    Thanked 30 Times in 29 Posts
    Quote Originally Posted by firepages View Post
    Alternatively (and not requiring .htaccess at all) you can use the server variable $_SERVER['PATH_INFO'];
    I am not sure you can do that without htaccess OR without access to httpd.confg.

    That is, when Apache catch a 404 error...it would look for a customized definition for 404 page. If none are found...it would use the default (the defaults vary depending on your distro).

    By the way...you can also use the script provided above with IIS...though some changes are in order.

    Instead of using $_SERVER['REQUEST_URI']...(IIS wouldn't have clue what you are saying here) you need to use $_SERVER['PHP_SELF']...or use $_SERVER['PATH_INFO'].

    cheers,
    ess

  • #7
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,040
    Thanks
    10
    Thanked 92 Times in 90 Posts
    the default apache1.* behavior is not to use a custom 404 (depending on flavour), thats setup in the httpd.conf or .htaccess , AFAIK the PATH_INFO and lookback features have to be disabled rather than enabled.

    That said almost all hosts have setup or allow custom 404's so there is nothing wrong with that approach , my effort was just another method to think about (and the one I personally prefer)
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •