Advanced - Need some advice about the directory / file structure

Discussion in 'Apache' started by johndoes, Sep 24, 2009.

  1. #1
    Hello everyone,

    I've changed all my dynamic URLs into fancy page names using .htaccess and rewrites.

    Currently I have seperate lines in my .htaccess that directs page names to id query strings like :

    /red-pc-game-pad -> /products.php?id=333
    or
    /brown-coffee-cup -> /products.php?id=22

    The biggest problem is, I have to put a seperate line for every product I have in the database. I have no way to use regex unless I include ids in the page names (like /22/brown-coffee-cup ). Now I see that this is a big flaw and the load increases with increasing product count.

    Then I examined Wordpress databases and saw that posts were match by their page names rather than post IDs. That requires a seperate (and redundant) index in the database. First question is:

    1) Is this the only way to use regex in .htaccess without including any ids on the URI?

    That is, I want /nintendo-wii to display /product.php?id=122. The way wordpress uses is to call the page with page_name like /product.php?page=nintendo-wii.

    This way I can put a single line of regex and direct all pagenames to
    /product.php?page=[pagename]

    Is there a flaw with this system? Or is there a better way to accomplish the rewrite more efficiently?


    The second question is about the directory / file structure. Currently all my items are displayed as if they are on the root of the site. Like:

    www.mysite.com/nintendo-wii
    or
    www.mysite.com/blue-coffee-cup

    As the number of products increase, I needed to divide them into categories. Like:

    www.mysite.com/consoles
    or
    www.mysite.com/cups_and_glasses

    However, if I keep the current file structure,

    www.mysite.com/nintendo-wii will be linked from www.mysite.com/consoles, but will appear as www.mysite.com/nintendo-wii
    rather than www.mysite.com/consoles/nintendo-wii

    2) What is your idea about keeping the product names at the root? If I move them under category names, then the URL will be longer and I may loose the current google rankings since pages are indexed as www.mysite.com/product-name


    3) If your advice is to move product names under categories, then is there a way to keep the current SE rankings while changing URLs from

    www.mysite.com/nintendo-wii
    to
    www.mysite.com/consoles/nintendo-wii



    As you may see I'm pretty confused and unsure. I know there's not a "right" answer for my questions, but I'm trying to install the most efficient
    system that I won't need to re-design in the future.

    Thanks for reading, any help greatly appreciated.

    Regards,
     
    johndoes, Sep 24, 2009 IP