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

Redirect Loop - Enhancing a Simple PHP App

I am struggling with redirecting my shirts.php in the .htaccess file.

The goal is to display shirts/ for the shirts/shirts.php file - in my case this file is located at /shirts4mike/shirts/shirts.php. When I click on a link to that page I get stuck in a redirect loop.

Part of my problem is that I have other projects on my MAMP root folder so I placed this project in a folder called shirts4mike located at localhost/shirts4mike.

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

Pretty sure I've tried all variations of rearranging the slashes and including absolute paths. Any thoughts?

1 Answer

If you're getting a redirect loop, then probably the error is not in the .htaccess file, but in the code.

However, just in case:

  • Try removing /shirts4mike/ from the path, and leave it as shirts/shirt.php
  • In MAMP, go to Preferences > Apache > and set Document Root to [whatever/path/you/have/before]/localhost/shirts4mike

The thing is that when you navigate to http://localhost:8888/ in the browser, you should see your Shirts4Mike site.

Hope this helps. If you still get the redirect loop, try to paste some of the PHP code.