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

JavaScript

Josh Alling
Josh Alling
17,172 Points

Lightbox stopped working after adding a rewrite rule

The homepage of a portfolio website I am working on has an animation on it, but I didn't want the animation to run every time the homepage is refreshed (because the homepage is also the portfolio page). I used php and a $_GET["id"] to make it so that the page only loads the CSS animation if the get variable is not set. Then I used a rewrite rule so that the url is /portfolio/ rather than /?id=portfolio.

Unfortunately my Lightbox no longer works with the rewrite rule. It follows the link to the actual photo rather than load the Lightbox, so it seems like the preventDefault line is no longer functioning. I don't know a lot about Javascript so I don't even know where to start to get this fixed. I have removed the rewrite rule to make sure that was the issue, and it works just fine without it.

Has anyone else had this issue, and does anyone know how to fix it?

1 Answer

Erik Nemesis
Erik Nemesis
13,356 Points

I think this is because when using the rewrite rule, you actually rewrite your url to get rid of your GET parameters. Therefore your $_GET['id'] will always be unset. How did you check your GET variable? Also could you please post some code (use jsbin or codepen preferentially)