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

Rewrite rules .htaccess and BASE_URL and WINDOWS 404 error

Problem working with Xampp and windows 32. Not reading the correct path to reach C:/xampp/htdocs/shirts/shirts.php

The link on main page “Hey, I’m Mike check out my shirts” gives Object not found! 404 Error localhost/shirts.php

The link in header “shirts” goes to Mikes full catalog of shirts, but they are stacked 8 down and not 4 to a row

.htaccess
RewriteEngine On
RewriteRule ^shirts/$ /shirts/shirts.php
RewriteRule ^shirts/([0-9]+)/$ /shirts/shirt.php?id=$1

config.php
RewriteEngine On
RewriteRule ^shirts/$ /shirts/shirts.php
RewriteRule ^shirts/([0-9]+)/$ /shirts/shirt.php?id=$1

I see other posts, but not real answer. Please help.

6 Answers

I am not seeing the entire picture, but I would initially look at the config of apache in XAMPP.

Try looking for this (or something similar)

  • Stop Apache
  • Click the Config button on the Apache row, and select httpd.conf
  • In that file, look for <Directory "C:/xampp/htdocs">
  • Below that heading you may see a line like this:

    # AllowOverride All
    
  • Remove the #, which is a comment, so that all that remains is

    AllowOverride All
    
  • Save the file

  • Restart Apache

Hopefully this works.

If not, try moving your project files over to a workspace and play with it there. Development environments can be trying for all of us at times.

Let me know if I can help further.

Hi Hampton, I did not see a "#" in front of AllowOverride All in Apache.

I am using win 32, Apache/2.4.10, Php 5.5. Please find my files at workspaces/5783752.

All is working good except:

  1. On the main index page on the header, clicking the "shirts icon" shows 8 shirts down instead of 4 across and also missing CSS.
  2. Hey, I'm Mike! Check out my shirts link returns a 404 error. I believe this is because the 2nd rewrite rule in .htaccess file. This is the directory tree I need to access c:/xampp/htdocs/shirts/shirts.php.

I am not using any additional directories like /Shirts 4 Mike/. httpd.conf had some discussion about server root C/xampp/apache.

I have been really struggling with this for the last 3 weeks. I see in the forum others with this problem, but no real solution.

Thank you for your help.

Thanks for your response. Please use the snap shot tool in the upper right hand corner of your workspace to share it with me. The url for that snapshot you can post here.

Thanks again!

Here is an image for reference.

oops! Use this one instead. It is complete.

https://w.trhou.se/t1l8a29048

There were a few things that need to be addressed, but nothing major.

Here is my workspace snapshot that you can use for reference if you like. https://w.trhou.se/1s6edoibht

To get your styles to work on your shirts listing page you will need to modify the class data from:

section page -> to -> section shirts

To get the link to work for Mikes call to action you will need to change the href on the index.php page to match the same url you use for the header.php navigation.

header.php

index.php

This will make the link work as expected.

Your code looks great! I think that your issue is not within the apache config.

Hope this helps you. Please let me know if you need further assistance, and thanks for being a treehouse student.

Works perfectly. You made my day. Thank you so much!