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

Not Having Much Luck Setting Up My .htaccess File And Redirects In The PHP Project!

Hi,

I have have re-installed the latest version of MAMP 3.0.5 and have set up my apache server and am using the folder htdocs where I have all my project files saved.

I have changed my AllowOverride None to AllowOverride All inside my config file. I have restarted my MAMP servers and I am still getting the following message.

"Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, you@example.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log."

If I delete the .htaccess file I am able to start the website homepage on

http://localhost/

As soon as I see save down the .htaccess folder I get the message above. I have saved the following code into may .htaccess folder again, and continue to get the above Internal Server Message error.

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

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

Please could someone shed some light on where/how I am going wrong?

Many thanks

Jon

2 Answers

Apologies just went back to the tutorial and was missing some some code at the end. All good now! Final code so was missing a two lines.

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

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

I have gone back through it all and it seems to work right up until i add the final rewriteCond then it breaks:-)

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

Is there something I have left off the code?