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 Introducing Rewrite Rules

I added the .htaccess file and unable to get the rewrite rule to work. Everytime I add the .htaccess I get an error

I am using a windows machine and I have XAMPP running Apache Server. I can go to localhost and see my listing. I click on the site I am working on and no porblems. I am trying to add rewrite rules to my php code. when I add the .htaccess file the page I am wokring on I get an error page error code 404 Object not found. not sure if it is that for some reason my apache server dose not have rewrite rules turned on and I do not know how to turn them on. Any Help would be great thank you

3 Answers

Hi Nathon,

try to apply these steps

http://milesj.me/blog/read/mod_rewrite-xampp-windows

Thank You Muhammad Mohsen, I followed the blog looks like everything was setup up the way it was suppose to be besides had to change on override to ALL. I still am having the same issue. Here is the code in my .htaccess file maybe I did something wrong in that. thank you again.

RewriteEngine On
RewriteRule ^shirts/$ /shirts/shirts.php
Derek Dawes
Derek Dawes
4,944 Points

As mentioned in another answer I had to do all these steps to get it to work on WAMP

(http://milesj.me/blog/read/mod_rewrite-xampp-windows)

<p>I followed the link above and removed the "#" from LoadModule rewrite_module modules/mod_rewrite.so in the httpd.conf file.</p> I also did a search in the document and changed all "override all's" If that confuses you just go to the link above it explains it.

Finally and not sure if its all I had to do but I had to remove the "/" before /shirts/shirts.php It now loads.

I also added a command in the .htaccess file that was mentioned in another answer as well

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

My problem sovlved by removing the "/" as you mentioned, thanks

Solved as well just by removing "/" before shirts/shirt.php

I had to enable rewrite_module on WAMP Apache first though