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 Rewrite Rules with Query Strings

htaccess rewrites everything except 1 url

Hey There. htaccess rewrites every url except 1. I followed along, the thing was to rewrite a url like this: localhost/shirt.php?id=106 to locahost/shirts/106/ Well every url does this (101 to 108) EXCEPT 106. I can not seem to understand this? Where can this problem be in? Every thing is in loops and the rewrite htaccess is not specifying 106 as to leave it out?

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

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

(.htaccess file)

My map name is phpdev This means I have to make my paths like this: localhost/phpdev/shirts/101/ (ex)

2 Answers

Philip Cox
Philip Cox
14,818 Points

The only thing I can see different to mine is, you have an extra directory, /phpdev. I placed mine directly i the htdocs folder so I new it was exactly the same. And you don't seem to have the last rewrite yet? RewriteRule ^shirts/([0-9]+)$ /$1/ [R=301]

Thanks for taking the time to help. Well it was not a problem of mine, it was a problem with chrome. Because it has cached the url in a certain way (the first time i typed it in my code wasnt ready) it set up the url like before. That's why the rest were all fine and one not. I tested it in internet explorer and firefox and everything worked fine.

But I do think this is a shortcoming on the behalf of Google Chrome.. Caching the url and not letting the htaccess rewrite it.. Weird

Jared Cain
PLUS
Jared Cain
Courses Plus Student 1,038 Points

I had this exact same thing happen to me as well. Every URL worked except the one containing ?id=108. After viewing it with no problems in Firefox, I reset my browser data in Chrome and it worked fine.