Jump to content
Larry Ullman's Book Forums

Recommended Posts

Before I buy this book on Amazon (i have an earlier edition), I just have to know...

 

Does the mod rewrite chapter detail how to change a blog post URL, from say the id and an integer, to the full name of the blog post? I would guess so, because the subtitle of the section is 'seo'.

 

I was trying to figure out how to do such a thing on Zend Server several months ago, but moved on to a different part of my project.

Link to comment
Share on other sites

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.

  • Upvote 2
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

I've used that approach for one example chapter. I don't use it exclusively, just demonstrating the concept. Yes, this book is set up differently than my others with the focus on learning individual concepts. The OOP sections have been greatly expanded in this edition.

Link to comment
Share on other sites

John and Lou:

I'm not sure exactly what you're talking about...maybe you can help me. I have the first part of modularizing a web site done, no problem. I'm using Apache2.2.22 in a Wamp setting. So my root for this exercise is www/ADV_PHP/ch02. I modified the htaccess file for that folder (ch02) exactly as was done in the examples and also my http.conf. Nothing happens for the mod_rewrite, even though I know it's on because you can put a check mark beside it through the Wamp interface. I'm thinking it might be a problem of versions--In my http.conf, the mod_rewrite module is listed with an extension of .so, and in the exercise it's mod_rewrite.s. Although I tried modifying it both ways in the htaccess file and nothing happened.

 

According to John:"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."

My question is, where are these x's and y's in the code? Do you mean 'p', which is what we're using? Exactly what are you talking about here? I don't think Lou is as much of a noob as I am so I need things to be spelled out very, very simply and directly.

Any help would be greatly appreciated!

 

Thanks!

Link to comment
Share on other sites

mod_rewrite has an extension of .so

 

Since your files are in a subdirectory, make sure your rewrite rules begin with ADV_PHP/ch02 or use the RewriteBase rule at the beginning. As for the x's and y's, John is saying that instead of using index.php?p=blah, you'd change that to /blah and have your rewrite rule use that value as $_GET['p'].

Link to comment
Share on other sites

 Share

×
×
  • Create New...