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


Rewrite Rules

Hi, I'm having trouble with getting the .htaccess file to work. I have the following written in that file (I'm following the Enhancing a Simple PHP Application course);

RewriteEngine ON RewriteRule ^shirts/$ /shirts/shirts.php

but all I get is an Object not found, error 404 page.

I have looked online to make sure that my XAMPP is edited to allow these Rewrite Rules eg;


LoadModule rewrite_module path/to/mod_rewrite.so

after LoadModule rewrite_module path/to/mod_rewrite.so

before AllowOverride None After AllowOverride All

Help! Ta!

5 Answers


Thanks for your help!

Was getting to a dead end with nothing working, turns out after trial an error, I've worked it out!

This is was what the second line said in my .htaccess file RewriteRule ^shirts/$ /shirts/shirts.php

This is it now says RewriteRule ^shirts/$ shirts/shirts.php

I removed the / from the beginning of shirts/shirts.php

And now it works!

Amazing the stress a backslash can give haha

Thanks for your help!

Chris Howell
.a{fill-rule:evenodd;}techdegree seal-36
Chris Howell
Python Web Development Techdegree Graduate 49,702 Points

If you are positive that your XAMPP is definitely set up correctly. Then recheck a few things.

1) Be sure your .htaccess file is located in the ROOT directory.

2) Make sure the directories you are referring to are going to the correct path, check spelling too. Sometimes your eyes don't catch an extra letter similar to the letter it sits next to.

3) Be sure you seperate each Rewrite command with a hard return.

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

(I dont know if you just wrote that piece of code on one line on accident, because you didnt know how to post it as code. To post as code you put 4 spaces then type the text you want as code. The MarkDown Cheatsheet is highlighted in blue in small print at bottom of this page for reference.)

Hey Chris,

Thanks for your reply.

step 1) .htaccess file definitely located in ROOT directory.

step 2) spelling rechecked and directories checked.

step 3) This was my error when i posted the code on here, just copied and pasted (noted for future posts). I have it set up as you've shown, with a hard return separating the Rewrite commands.

Made some progress though, I guess, I added a / to ^shirts/$ so now it reads ^/shirts/$. Now when I load http://localhost/shirts4mike/shirts/ in my browser, I get an Index of shirts4mike/shirts showing the shirt.php and shirts.php files.

Back at that road block again.


Chris Howell
.a{fill-rule:evenodd;}techdegree seal-36
Chris Howell
Python Web Development Techdegree Graduate 49,702 Points

So it seems like the problem may be with the XAMPP server's mod_rewrite. Because it basically acting like the rewrite isn't there. I will see If I can find anything on XAMPP rewrite. I am using WAMP and it was just a simple click enable for me to turn rewrites on. I havent used XAMPP version so im not entirely sure on the differences in activating it.

Chris Howell
.a{fill-rule:evenodd;}techdegree seal-36
Chris Howell
Python Web Development Techdegree Graduate 49,702 Points

Here found this, try reading through this and make sure your XAMPP conf file matches. Read through the comments below instructions. Try that, restart your XAMPP server and try your rewrite rules again, see if it loads the index list of everything contained in the folder or the actual page.

Iffy on how accurate this info may be, the posts are fairly outdated.