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 Enhancing a Simple PHP Application Cleaning URLs with Rewrite Rules Redirecting Old Web Addresses

saranyamoellers
saranyamoellers
31,691 Points

why my page doesn't show up when I typed localhost/shirts4mike/reciept.php in URL?

According to the video Redirecting Old Web Addresses in PHP I typed localhost/shirts4mike/receipt.php in the URL like Randy did My thank you page wouldn't show up I had Forbidden Error instead but If I typed localhost/shirts4mike/receipt/ my thank you page would work. I was wondering why I got the error ? do I need to fix something in the Apache config file? Please help.

Logan R
Logan R
22,989 Points

Can you please provide the code for the .htaccess code so we can look? Thanks!

saranyamoellers
saranyamoellers
31,691 Points

Do you know how can I show my code in the black background like other did?

Logan R
Logan R
22,989 Points

Press enter then type three ` then press enter then your code then press enter then type three of the things again. For a visual example, watch the video on the right, Tips for asking questions (click the image).

Changed it for you. :)

Sorry, I didn't see your comment below with the syntax highlighting. I edited your above comment to add the highlighting.

saranyamoellers
saranyamoellers
31,691 Points

thank you anyway. You did much better job than me. I didn't know someone else can edit my code :)

2 Answers

Logan R
Logan R
22,989 Points

This is because you have not accounted for leading slashes yet. Randy will go over this in an episode or two. For now, just note that if you do URL/ it will work, but URL will not.

Rewrite sees these two URLs, URL/ and URL, as two different addresses.

Hope this helps you out!

(Edit: You can view the video early here: http://teamtreehouse.com/library/enhancing-a-simple-php-application/cleaning-urls-with-rewrite-rules/adding-a-trailing-slash )

saranyamoellers
saranyamoellers
31,691 Points

My URL/ or URL both already works. localhot/shirts4mike/receipt/ or this localhot/shirts4mike/receipt (they work) I was talking about localhot/shirts4mike/receipt.php (this is the old address) would not work. Thank you for your time.

saranyamoellers
saranyamoellers
31,691 Points
 <p>
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]
</p>
            ```
Above is my htaccess file