Jump to content
Larry Ullman's Book Forums

Chapter 7: Ex 2 Site: Help with Rewrite rules and file referencing:

Recommended Posts

Hello Larry,

Thank you for the publishing of your book. We are using it at school to learn development of an e-commerce site. 

I wanted to share with you an issue me and some of my classmates have run into in chapter 7. I am testing the ex2 site locally with the following specs:

PHP 7.1.33

MySQL 5.7.28

using Local.app by flywheel to run local Apache server

Using PHPStorm to run and debug my code.


It seems like my .htaccess rules are not working, but I am not sure why the rules are not redirecting correct, Kind of having a hard time understanding if it's the htaccess file or  my headers.html, or home.html files?  I attached a zipped file of my configurations. The code in my htaccess file is just like the Ex2 2016 code download, except I have subdirectories "/homework/ex2/html/" as the rewriteBase value (2nd edition book, page 201, Using Subdirectories).  We were asked to place our site files into a subdirectory. I'll attach my htaccess file, headers.html, and home.html in a separate zip file (Files-modified-ex2site.zip).

The main issues is that my secondary links to the site sections are producing broken images. I explain this in more detail in the Chapter 7 bugs zip file. I have tried multiple relative and absolute path edits, but the current set up is the best I could figure out to access most of the files on my local test browser.

Any help is appreciated.

Chapter 7 Bugs to fix.zip Files-modified-ex2site.zip Chapter 7 Bugs to fix.zip

Link to comment
Share on other sites

I'm not sure what you mean by "secondary links" but if you're seeing broken images, the HTML references to those images are likely incorrect. The image should not be affected by any rewrite rules.

What is the URL you're using to test locally (for a page that works)? What HTML are you using for one of the links that's broken? Where are the images stored locally?

Link to comment
Share on other sites

Thank you for responding to my post. By secondary links I mean the coffee site sections: Coffee, Goodies,  Sales, Wishlist, Cart.


The URL that works is my index.php page that includes the Sales items image from the /view/home.html page in the index.php:



The images in the coffee shop.php url : are broken. I can see that part of the reference is missing which is "/homework/ex2/html/ " , but I do not understand where they are being referenced. Please excuse my lack of debugging experience I am new at web development.



Link to comment
Share on other sites

The general site resources--images and such--are referenced in the header file, so the HTML there needs to be correct. In your case, they need to start with the "/homework/ex2/html/ " bit.

The HTML for images for specific products is created by the PHP scripts, like shop.php and browse.php. You need to make sure those scripts are outputting the correct HTML, including the "/homework/ex2/html/". 

As a debugging tip, if your dark_roast.jpg image is in the "<webroot>/homework/ex2/html/products" folder on your computer, the proper HTML reference to that image is "/homework/ex2/html/products/dark_roast.jpg". You can confirm this but loading http://web260.local/homework/ex2/html/products/dark_roast.jpg directly in your browser. Once you have the right HTML to view an image directly in your browser, you know you have the right HTML to put within your code. 

Link to comment
Share on other sites

Larry thank you so much. I used your suggestions and they helped to me to work out the references for specific products in the Coffee and Sales content:





When I looked further into the sales.php and shop.php scripts require(./views/list_categories.html) and  require(./views/list_sales.html) I found the html references to append "/homework/ex2/html"  in those html files, located in the views directory.

I will continue on debugging the goodies,wishlist, and cart sections.

If I do run into issues with those would it be better to create another post for that inquiry?




Link to comment
Share on other sites

Glad it's working and thanks for letting us know. If you have any additional questions or problems with this particular issue, post them in this thread. If it's a new concern, a new thread works. 

Also, while oversharing details is better than undersharing, I don't think anyone's going to download and look through a folder of code. Best just to put all the context in the post itself.

Good luck with your class!

Link to comment
Share on other sites


  • Create New...