Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

Joel Rivera
Joel Rivera
29,401 Points

Enhancing a Simple PHP Application

***UPDATE: I got the shirt page to work. Not sure how I did it but when I go to look in the browser and click on the links they don't recognize the links. I'm using the BASE_URL where needed and including the config file.

I'm thinking it has to do with my file structure and the RewriteCond and RewriteRule. As noted below I have several websites in my htdocs. So I have the shirts4mike in it's own folder. How do I adjust the .htaccess to reflect this? Thanks SMH. HELPPPPP. Thanks

Hello All,

I am having an issue with my shirt page. It is not rendering and displays a 404 Page.

My shirts page displays fine and works but for some reason I can't seem to get the shirt page to work.

I've gone over the .htaccess file several times and it seems to be correct.

Only thing is since I have several sites I'm working on and saved in my htdocs folder, I have made a shirts4mike folder with all the contents saved in there. I have compensated by making sure all the files reflect that and the contact page is working, receipt page is working, shirts page is working but the shirt page is not working.

I was wondering if anyone had any ideas. Below is the code for the .htaccess file.

RewriteEngine On RewriteRule ^shirts/$ /shirts/shirts.php RewriteRule ^shirts/([0-9]+)/$ /shirts/shirt.php?id=$1 RewriteRule ^receipt.php$ /receipt/ [R=301] RewriteRule ^contact.php$ /contact/ [R=301] RewriteRule ^shirts.php$ /shirts/ [R=301] RewriteRule ^(shirts/[0-9]+)$ /$1/ [R=301]

RewriteCond %{QUERY_STRING} ^id=([0-9]+)$ RewriteRule ^shirt.php$ /shirts/%1/? [R=301]

2 Answers

Walden Wang
Walden Wang
5,657 Points

I have same situation for the .htaccess.

You can try to update the code like this:

RewriteEngine On RewriteRule ^shirts/$ /shirts4mike/shirts/shirts.php

Can you provide more information on your sites file structure?

Joel Rivera
Joel Rivera
29,401 Points

I have the HTdocs in there I have folders for various websites so I created a folder for shirts4mike.

in that folder I added all the content as your tutorial has it. To compensate for the addition of the folder I made the config file look like this

<?php

define("BASE_URL","/shirts4mike/");
define("ROOT_PATH", $_SERVER["DOCUMENT_ROOT"] . "/shirts4mike/");

Otherwise everything else is the same. I am thinking it has to do with the .htaccess and the regular expressions which I did exactly as was mentioned in the tutorial.

NOTE: I am working on a macbook pro using mamp and dreamweaver cs6.

Obviously I can be completely wrong on where I think it is wrong. I did try and keep the same file structure otherwise.

Thanks for your help.

I have a similar problem, because I was getting alot of websites under htdocs (on my development server ie http://localhost), I created a folder called "EnhancingASimplePHPApplication" (within the "htdocs" folder). I copied all the files for "Shirts4Mike" into there. I have followed along with the video ("Using Root-Relative Web Addresses"), but the "root relative absolute URLs " in my header file are not working.

I'm left wondering why, because if you use "/style.css", this should work, as it starts searching from the root directory, until it can find the file.

The "style.css" is in a directory "EnhancingASimplePHPApplication /css/style.css".

The PHP script I'm running is in "EnhancingASimplePHPApplication/receipt/index.php". This script accesses the header file. It is within the header file, I placed all the root relative urls. None of which seem to work.

How does one get the root relative URLs to work when a directory other than "/" is used?

I got this to work, this mistake was mine. The relative absolute urls were working, I just didn't recognise it, apologies to all concerned.