Skip to content

Files & Folders >> Virtual Pages

DeeeeeeeeDeeeeeeee the Americas
edited December 2020 in Other / Off Topic
Re-doing an old site. I could go to WP or something but I'm not. Why? What I have is lean and pretty fast. No need for all the extra stuff WP offers. Anyway...
I have a few resources that list states. It actually has fifty folders with fifty index files and associated content files for each! :scream:
I want to virtualize. What's the best way for SEO?
htt p://example.com/states/New-Jersey
-or-
htt p://example.com/states/index.php?state=New-Jersey

Anyone have any links on how to do this with PHP and apache? A while back I asked about how to generate dynamic URLs in PHP, but I actually ended up already knowing how to do that, just didn't know the correct terminology for what i actually wnted to do and forgot all about it but today figured out what might be the right term, and it was.
I know ZenCart and WordPress and every CMS does this, and I see it's with ModRewrite in .htaccess.
P.S. I realize I have to include the correct content for each page via file or DB, it's the actual creation of a virtual page I don't get.

Comments

  • SvenSven www.GSA-Online.de
    The best is of course not to use any "?" in the path. A "?" will cause a none cache behaviour in all browsers.
    Also try to use for the slug: a-z, 0-9, - and nothing else. Even using "_" is considered a bad behavior (gsa-online.de uses it for historical reasons).
  • DeeeeeeeeDeeeeeeee the Americas
    edited December 2020
    Hmmm..Thanks, Sven.  Ahhh...I see....That's how I get a page to load uncached. I used a dummy parameter after the URL with a ?

    No caps, tho? In recent years I tired to get away from caps, just b/c it's more difficult for users to type in a page manually...but still have some older pages with caps.
  • SvenSven www.GSA-Online.de
    A "?" at the end of an URL was always using no-cache. No need for dummy parameters.
    Using capital chars is considered to be no good practices. It's of course not against any rules but it just looks nicer to have everything lowercase.
    Thanked by 1Deeeeeeee
  • DeeeeeeeeDeeeeeeee the Americas
    edited December 2020
    Sven, what if THIS site in particular I'm working on improving Has All Caps In URLSs? (later, I stopped doing this with newer sites bc I realized users can't type that as accurately..I mean you could have it so it accepts both but...)

    Should I keep existing URLs Upper Case or change them all for SEO reasons to lower?

    If it's already all upper case, should I stick with what I did already, and NOT use lower case? Or, just slowly change over as I re-do pages?? Starting here?

    Thanks...

    EDIT: Sven, and anyone else around...I decided to keep it Upper Case. Why? These are EXISTING URLS! And they are uppercase already. I'd have to 301 to every new (virtual) URL. Which is doable., but I am just keeping it all consistent for now, Maybe one day later I'll go lower case, but I just want to  get this virtual URL thing down for now! Wow...No longer need to make folders and files...
  • DeeeeeeeeDeeeeeeee the Americas
    edited December 2020
    Found way to do this:
    <IfModule mod_rewrite.c>
        RewriteEngine On
    
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteRule ^(.*)$ index.php [QSA,L]
    </IfModule>
    
    in .htaccess
    and
    if (strpos($<code>pagetoshow , 'chairs') !== false) {
        echo 'Chairs'; $Itme= "<code>Chairs";<div><br></div><div><code>$pagetoshow = $_SERVER['REQUEST_URI'];

    in index.php

    and then just conditionally display all the different possible content and different meta settings using that one index.php file....
    while the new page displays...
    What about if I just put in
    ht tp://site.com/Items/Tables(<-- oops, Sven!) <br>
    <br>
    and there IS no "Tables" page to display?
    <br>
    The URL will show as TABLES even tho you'd have to say 404...
    I guess then you'd have your PHP file redirect to a 404 error page on the two conditions of no match AND not simply being the root directory with no other characters after it. You also need to be able to hit the root directory.

  • DeeeeeeeeDeeeeeeee the Americas
    edited December 2020
    This is overbroad solution.
    What if user types: htt p://website.com/chairsandtables
    as I have it above it will still go to chairs page...
    needs to be precise match to URL
    else it could create a mess for SEO and duplicate  pages!!
  • SvenSven www.GSA-Online.de
    but duplicate content is handled already by <link rel=canonical ..> ?
  • DeeeeeeeeDeeeeeeee the Americas
    edited December 2020
    "but duplicate content is handled already by <link rel=canonical ..> ?"

    True. So I guess technically you COULD have a site that will take you to a page if the user just types a web address that even contains PART of the correct folder (and/or  file if you're not just using directories) Still, that seems messy, semantically, if nothing else.

    In a sense it's OK, bc a user can mess up and still get to where they're trying to! :p

    So which way is better, then? Hmm...
  • SvenSven www.GSA-Online.de
    Redirect with 301 to it.
    Thanked by 1Deeeeeeee
  • DeeeeeeeeDeeeeeeee the Americas
    edited December 2020
    OK, cool. (E.g.) I can make the site more usable if I allow sub-string pattern matching for like "nail"  and then 301 to the "actual" precise canonical page. So the URL as a sort of internal page "search."

    It seems cool to be able to get where you need to by just typing any of these as a user:
    ht tp://website.com/inventory/nails-for hammer/
    ht tp://website.com/inventory/nails/
    ht tp://website.com/inven/nails/
    ht tp://website.com/inventory/copper-nails/
    ht tp://website.com/inventory/copper-nails/
    ht tp://website.com/copper-nails/
    ht tp://website.com/nails/
    ht tp://website.com/nail/
    ht tp://website.com/aluminum-nails-andshelves
    ht tp://website.com/some-sort-of-nail
    ht tp://website.com/some-sort-of-nail_half-imnch
    ht tp://website.com/COPPER_NAILS_FOR_CARPERTING

    Nails are  a poor example as there can be so many different types of nails and this would make the most sense on a site with fewer pages. If this were for a cart selling nails, the cart would most likely just display all matches as  the returned page results. (Would that require more extensive use of apache MOD_REWRITE, tho to turn the URL into a search string on the cart?)

    I am experimenting with using this right now just to load the right page on a web site, not inventory on a cart. But same benefit: You can make the user experience THAT much more error-and-hassle-free free even with typo-prone users.

Sign In or Register to comment.