Jump to content
Larry Ullman's Book Forums

Lou

Members
  • Posts

    97
  • Joined

  • Last visited

  • Days Won

    2

Posts posted by Lou

  1. Let me try to write this in some kind of psuedo code.

     

    1 On my pages link the individual blog posts with their title, like articles/row(from database)/title-of-post (from the database row), not just details.php?article_id

     

    2 Create a rewrite rule that matches the link (articles/whatever ever comes after it), stores the row and title in a variable like $1 and $2, then run details.php?article_id=$1. I guess I only need the article id then.

     

    3 The details.php script executes like before, but the user sees the pretty URL, not the mess with the query string

  2. Okay I went back to read some. Stupid me. I'm thinking that the links have to be details.php?article_id=2 instead of just inserting the title of the post into the link like Hartley showed me. I don't know why I thought the first way was the only way. Probably because in one of the books I'm reading they do it that way, and instead of trying to solve the issue in a different way I stayed rigid in the original link format.

     

    Another question though. If I change the links to the blog posts to the article id/name of blog post format, what happens to details.php that originally handled whatever post I pulled up, let it be article_id 1, 2, 3, 4, 5, or 100? How would I get to the details.php page if the link is already the name of the article?

  3. Still confused but getting there.

     

    Say you have your details.php page and it's showing article 2. details.php?article_id=2

     

    You do your rewrite rule to change the url to articles/my-article-title, taking the info from details.php?article_id=2.

     

    I still don't get how you get the title of the article into that new URL. Where does it come from? It seems to be going in the wrong order. How does your regular expression pull the title out if the link is article_id=2?

  4. I am building a dating site. Figured I'd start simple, but the few things I don't understand have stopped me from completing it thus far.

     

    Clean URLs for the blog section (mod rewrite)

     

    Database structure (user table, profile table, etc). I find it really hard to figure out what's going into the database and specific tables.

     

    I know how to make a user's image gallery, but how do you let them define a main photo? do you put that main photo in their profile table, or just in the photos table? Can you define a main photo by say, a 0 or 1 in the photos table, or always keep their main photo in their profile table?

     

    If you store sessions in a database using procedural mysql (Larry writes the six functions in the advanced book), can you connect to the database for other tasks using PDO or object oriented?

     

    I can get distances between users from my zip code database, but how would I implement users from other countries? i see on other dating sites they let users sign up from different countries and territories. do you have to determine distances for those users as well, and if so, how? Or should I just keep the site USA only?

     

    See I have these weird questions one needs to actually complete a site but is rarely covered in any book. :)

  5. I thought Lou meant the site in the link belonged to him* I just now visited it and it seems like it was just something he* was referencing. My bad.

     

    *Him, right? I don't see a gender listed in Lou's profile, so I assumed based on the name. (I knew a guy named Lou once.)

     

    - - - -

     

    I am also wondering something. Since the title is only in the URL for the benefit of search engines, does it even have to be unique?

     

    No I haven't completed any site yet. I've been reading PHP, MySQL, HTML5 books for 3 years and haven't come close to completing a real site yet. I have every one of Larry's books except this new Advanced one. I can code, but I lack a plan for putting it all together. Basically, it's a database problem.

  6. mod_rewrites are also covered in the Effortless Ecommerce book. For some reason, it took me awhile to master writing clean urls but I have managed it on my site. Have a look and see if that is what you require. Here's the code from my .htaccess file

    <IfModule mod_rewrite.c>
    RewriteEngine on
    #RewriteBase /
    
    RewriteRule ^archive/([A-Za-z0-9-]+)/?$ archive.php?a=$1
    RewriteRule ^blog/([A-Za-z0-9\+\-]+)/([0-9]+)$ blog.php?t=$1&id=$2
    RewriteRule ^blog/$ blog.php
    ErrorDocument 404 /404.php
    </IfModule>
    

    Be sure you update the links as well or they won't work.

     

    I don't see how this RewriteRule works. I'd like the title of the blog post to be part of the URL of the blog post, I don't want the URL to be article_id=2. It looks like these rules make sure the URL is in the format I don't want. Can you explain each line?

  7. I don't get it.

     

    1. If you're dynamically pulling say the first 5 blog posts from the database into your blog.php page, how would the links already be the titles of the blog posts?

     

    2 One of the links on the main blog page would be say.... details.php?article.id=2. You click the link and you're on the details.php page and the query string pulls all the info from the database for the article requested

     

    3 When working with mod rewrites, would the links on the main blog page still be say article_id=2, then when you click the link, the mod_rewrite rules take effect and you're redirected to a different link that's the title of your blog post?

     

    4 I just don't see where the link would get the title of the blog post

     

    I don't even know the right question to ask right now. :)

  8. Still confused. I only got up to making sure the rewrite engine is on and redirecting to my index page when a user goes to a page that doesn't exist.

     

    I'm using this site by the way.

     

    http://blog.webilix.com/2012/10/implement-seo-friendly-urls-with-mod_rewrite/

     

    I'm using xampp by the way, not ZendServer anymore. ZendServer was okay but I couldn't test any SSL with it.

  9. I'll definitely have to check out the book then. It's just so confusing, but it is an advanced topic. I know how to make clean URLs by putting an index page inside each directory, but using the blog post for the page title has alluded me this far. Amazing how every book tells you most of what you need, but there are several important things always left out that you NEED to make a complete site.

  10. What I would personally do, is just have the article_id coming in from the URL and nothing else. I would have that page use the article_id to query the database and have the database give it all the details: the full post, the title, and whatever other information you want. I wouldn't want to rely on this information coming from the URL because then anybody could tamper with it. I guess you could prevent this by validating all input, but just getting the data from the database seems easier.

     

    I hope this helps :)

     

    I don't think this answered my question. How do I make the URL the name of the post isntead of article_id=2? When you select an article from the main blog page, you're taken to a details.php page that displays the blog post you selected. I want that page's URL to be the name of the post and NOT article_id=2

  11. Back again... I'm putting this in the advanced section. I'm not sure if this is covered in the new book (I have the previous edition) or not.

     

    Say you have a blog page with a few articles. The user clicks on an article and goes to a page with the complete blog post. The title of the page includes the query string for the article, like details.php?article_id=2. How would you make the title of the individual blog post page something like this-is-the-title-of-the-blog-post instead of details.php?article_id=2?

     

    Thanks a bunch for anyone who can clue me in. :)

     

  12. Hello Lou.

     

    The "Improved SEO with mod_rewrite" section of Chapter 2 does an excellent job of teaching how to change a site's URL from a root URL with a bootstrap $_GET suffiix, which you described, to root URL with an easily interpreted apparent directory structure. If you already have a bootstrap modular site like the one Larry teaches in the first part of chapter 2 ("Modularizing a Web Site"), the conversion using mod_rewrite will be simple.

     

    If you are implementing both of the first two sections of Chapter 2 for the first time, note that the last essential step of using mod_rewrite is so simple that Larry mentions it as a tip rather than an enumerated step: "Once you adopt this system, you'd want to change the URLs for the links (in the HTML), and the action attribute of the search form." In fact, you will not have adopted this system until you complete this tip.

     

    To complete the tip, in all action='x' or href='x' code where x references a part of your site that is enumerated as a case of the main switch, just replace x with the name y from case 'y'. Simple. Elegant. Brief.

     

    Two other points worth noting:

    1. You probably will not want to list all your site's pages in index.php's master switch. Pages that should not be accessible except until login validation or further processing are probably generally left with a bootstrap $_GET suffix.

     

    2. Larry demonstrates fairly minimal expressions in the index.php cases. You can expand this to specify page-specific header elements or other things.

     

    Wow, what an explanation. I have read about 10 php books and struggled to read what you wrote. :-) I don't usually code with an index.php that's a master switch (MVC style). Has Larry adopted this style for this new Advanced book? I'll have to buy the book and read this material, it sounds interesting. I enjoyed the previous Advanced book, but haven't read that one in awhile since it's set up differently than his other PHP books.

×
×
  • Create New...