SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Wizard
    Join Date
    Jul 2003
    Location
    Corner seat
    Posts
    1,069
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Making websight(php directory script) user/search engine friendly

    Websight http://websight.sourceforge.net/site/ is a directory script written in php. I just modified it so that all URL strings will be user/search engine friendly. I'd like to present a short tutorial/article on how to do it and share with you all today. Now I know that this is not the best way to make URL strings user/search engine friendly, though it works. I also know that a lot of improvements can be made. However, I what I'm hoping to accomplish is

    1) If anyone else out there trying to create a user/search engine friendly directory, then they can just look at this short tutorial and do it.

    2) I'd expect fair amount of criticism; as I answer those criticism, I can improve my work.

    Ok, here we go.

    1. First, you create pathinfo.php and place it in the root of the installation directory. The file looks like this
    Code:
    <?php
    $GetCategoryId=Array();
    $MatchCategory=Array();
    
    $GetCategoryId["/Journals/"]="1";
    $MatchCategory["1"]="Journals/";
    $GetCategoryId["/Adult_and_Continuing_Education/"]="4";
    $MatchCategory["4"]="Adult_and_Continuing_Education/";
    $GetCategoryId["/Career_and_Vocational/"]="5";
    $MatchCategory["5"]="Career_and_Vocational/";
    $GetCategoryId["/Chats_and_Forums/"]="6";
    $MatchCategory["6"]="Chats_and_Forums/";
    
    ...
    
    if ($cat == "0")
    {
        if (strlen($PATH_INFO) > 1
            && $PATH_INFO{strlen($PATH_INFO) - 1} != "/")
        {
            $cat = $GetCategoryId[$PATH_INFO."/"];
        } else
        {
            $cat = $GetCategoryId[$PATH_INFO];
        }
        if ($cat == "")
        {
            $cat == "0";
        }
    }
    ?>
    Basically, this maps url strings to different categories and vice versa.

    2. Copy index.php and name it Top(no extension)

    3. Include the following line
    Code:
    include_once("./pathinfo.php");
    in confirm.php, privacy.php, search.php, Top, newcat.php, contact.php, index.php, and newlink.php, right after
    Code:
    include_once("./includes/functions.php");
    4. There are functions to check if the file called is index.php. Modify them so that both index.php and Top are recognized.

    5. ?cat=xxx needs to be replaced with new directory path; you need to do two things to do this.

    i) You need to reference $GetCategoryId and $MatchCategory, get new directory paths and save them in an array.

    ii) You need to reference the array to get new directory path for each and every ?cat=xxx.

    6. Add the following code wherever appropriate depending on your server configuration(.htaccess or vhost.conf).
    Code:
    <Files Top>
        ForceType application/x-httpd-php
    </Files>
    That's it! Tutorial is rather brief(actually very brief), so there are a couple of things you need to figure out, but you should be able to figure it out. I barely know php, so if you know php just a little, you should be able to figure out details.

    Again, I know that this is not the best way to do it. A lot of improvements can be made(easily). Let me know and post comments, suggestions, and questions if you have any. Hopefully, we will have OK tutorial here so that less people will be struggling to make a user/search engine friendly directory from now on.

    Second Last Note: This is one example of how it's done; http://www.cgedonline.net/dir/en/.

    Last Note: If there is someone who is pretty good at php and wants to rewrite this and publish an article(on sitepoint?), please do so. That would help me as well as other people.

  2. #2
    SitePoint Guru Nick Carlson's Avatar
    Join Date
    Aug 2003
    Location
    Denver
    Posts
    644
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you so much for this!

    By the way, do you know Japanese?
    ncarlson.net - a programmer's dystopia

  3. #3
    SitePoint Wizard
    Join Date
    Jul 2003
    Location
    Corner seat
    Posts
    1,069
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you so much for this!
    Please post questions if you have any; I'd like to clean this up and make it better as I try to answer those questions.
    By the way, do you know Japanese?
    Yes, why? My writing in Japanese is not that strong though(I do know that you have subtitle in Japanese right under your username optimus prime and it says "Optimus Prime " in Japanese; I've been noticing that for a while now).

  4. #4
    SitePoint Guru Nick Carlson's Avatar
    Join Date
    Aug 2003
    Location
    Denver
    Posts
    644
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I made a similar hack for phphoo, but I didn't really like to script to begin with. I plan on making a few new directory sites with the use of websight and your edit you have here.
    I'll post when I run across some questions.

    I've been studying Japanese for about 3 years. I spent one year in Japan going to school as a senior, and I'm actually going back in June to teach english at a private school for 15 months. Then right after that, I have to return to Tokyo to attent Sohpia University. Hopefully, I'll get close to becoming fluent by that time.
    ncarlson.net - a programmer's dystopia

  5. #5
    SitePoint Wizard
    Join Date
    Jul 2003
    Location
    Corner seat
    Posts
    1,069
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I made a similar hack for phphoo, but I didn't really like to script to begin with. I plan on making a few new directory sites with the use of websight and your edit you have here. I'll post when I run across some questions.
    That's great. When you become some rock star php directory developer and rick and famous, don't forget about a humble fellow you met at sitepoint .

    One tip. See here ...
    Code:
    $GetCategoryId=Array();
    $MatchCategory=Array();
    
    $GetCategoryId["/Journals/"]="1";
    $MatchCategory["1"]="Journals/";
    $GetCategoryId["/Adult_and_Continuing_Education/"]="4";
    $MatchCategory["4"]="Adult_and_Continuing_Education/";
    $GetCategoryId["/Career_and_Vocational/"]="5";
    $MatchCategory["5"]="Career_and_Vocational/";
    $GetCategoryId["/Chats_and_Forums/"]="6";
    $MatchCategory["6"]="Chats_and_Forums/";
    Websight stores all these directory names in the database; I was lazy and I hard coded full directory paths, but you can write a short routines to generate all these full directory path strings dynamically. If you do that, all you need, all anyone needs is to set
    Code:
    <Files Top>
        ForceType application/x-httpd-php
    </Files>
    to create, what they call, user/search engine friendly directory. I don't think there is any directory script that can create user/search engine friendly directory upon installation(is there?). So if you do this, there is a good chance that you will have good install base; you can be pretty famous doing this.

  6. #6
    Aussie Icon ozgression's Avatar
    Join Date
    Jul 2002
    Location
    Australia
    Posts
    839
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi. I need clarification on this:

    Code:
     
    $GetCategoryId=Array();$MatchCategory=Array();
    $GetCategoryId["/Journals/"]="1";$MatchCategory["1"]="Journals/";
    $GetCategoryId["/Adult_and_Continuing_Education/"]="4";$MatchCategory["4"]="Adult_and_Continuing_Education/";
    $GetCategoryId["/Career_and_Vocational/"]="5";$MatchCategory["5"]="Career_and_Vocational/";
    $GetCategoryId["/Chats_and_Forums/"]="6";$MatchCategory["6"]="Chats_and_Forums/";
    So I put

    Code:
    <Files Top> ForceType application/x-httpd-php</Files>
    in phppath file? Instead of the above code with the folder names?

  7. #7
    SitePoint Wizard
    Join Date
    Jul 2003
    Location
    Corner seat
    Posts
    1,069
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    in phppath file? Instead of the above code with the folder names?
    Let me clarify.
    Code:
    <Files Top>
        ForceType application/x-httpd-php
    </Files>
    This particular code is for the server(Apache) configuration. Generally, there are two ways to add this code in Apache configuration.

    1. Create .htaccess file, add the code and then add the file in any directory lower than the directory that you run your Websight. For example, if you happen to run your copy of Websight on www. yourSite.com/HealthCare/CoolWebsites/ then you need to put your .htaccess on

    www. yourSite.com
    www. yourSite.com/HealthCare or
    www. yourSite.com/HealthCare/CoolWebsites

    (Anyone out there, if I'm wrong, please correct me.)

    2. You can just add the code in vhost.conf. I don't know exactly what kind of environment you are running your website in, but if you have vhost.conf file for your own website, then this is more preferred method.

    There are a bunch of messages posted in forums and tutorials that discuss ForceType, but let me reference a couple of them out there.

    http://www.devarticles.com/c/a/Apach...cer-Page-URLs/
    http://wiki.asleep.net/ForceType
    http://forums.devshed.com/archive/t-89507

    Please remember that, if you are using Apache 2.x, you might experience some problem and you might need to do this a little differently. You are using Apache 1.x, aren't you? Basically, what you need to do is to tell your web server that Top is actually a php file and it needs to be interpreted and executed as it is php.

    (Anyone out there, if I'm wrong, please correct me.)


Bookmarks

Posting Permissions

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