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

Problem with RewriteCond, causing Error 500 on my server

I am trying to strip out a single level of my new written directory to avoid repetition of entity names in my URL. The specific name of "Well service" is duplicated as I am passing both the page category and pump category to the URL to render the page and perform relevant queries.

My current URL looks like this http://mysite/Wellservice/Well-Service/PumpID01

Although this is not a major problem from an aesthetic perspective I would like to clean the URL up further by stripping one level of "Well Service" from the URL to create something that looks like this: http://mysite/Well-Service/PumpID01

I have tried to build a query to handle this but it causes the server to respond with an Error: 500, my query can be seen below:

 RewriteCond %{QUERY_STRING} ^?id=([\w-]+)&s=Wellservice&c=(Well-Service)$
 RewriteRule ^product.php/?$ /Pumps/%2/%1/? [R=301,L]

Have I done something wrong in my code for the Error 500 to be returned, or is it not possible to do what I am trying to do.

NOTE: +Variable "id" = the pumps id to query the database +Variable "s" = the category the pump belongs to to refine query result +Variable "c" = the page category to generate any page specific styling including active state

1 Answer

I'd confirm that the original, non-rewritten url works great without the rewrite rule in place first, just to make sure you're not accidentally getting a 500 from the page itself. If you're not, you'll want to make sure you've got an Apache error log running and review it to see what the details of the 500 are.