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

Derk van der Heide
Derk van der Heide
11,472 Points

Weird RewriteRule problem

@Randy Hoyt

I just watched all the RewriteRule videos from Randy Hoyt. I seem to be having a weird problem with the RewriteRule for adding a trailing backslash.

These are my rules, I modified them a bit, as I have everything in a subfolder caled Shirts4Mike:

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

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

Everything seems to be working, like when I go to http://localhost/Shirts4Mike/shirts/104 without the backslash, one gets added and I end up on the correct page.

Except JUST for the number 102, it doesn't work. When I go to: http://localhost/Shirts4Mike/shirts/102 I end up at: http://localhost/shirts/102/

Also when I remove all the rules from my .htaccess file, it keeps happening. What could possibly be causing this?

Try two things: Restart the web server. Clear the cache and history of the browser.

Derk van der Heide
Derk van der Heide
11,472 Points

Thank you! Clearing the cache did it :)

geoffrey
geoffrey
28,736 Points

Jeff Busch would you mind posting your comment as an answer, this way we can mark it as best answer ? :)

1 Answer

Try two things: Restart the web server. Clear the cache and history of the browser.