Get a free trial // Grow your CSS skills // Land your dream job

PHP Switch/Case and the Dreaded Unclean URLs

  • # March 19, 2013 at 5:35 pm

    Maybe try

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /index.php?page=$1 [NC,L]

    # March 19, 2013 at 5:35 pm

    Ok, can you write that into what I posted, because I have a feeling I’m missing something…

    # March 19, 2013 at 5:37 pm

    Actually, ya know what that last change you made to the mod_rewrite fixed it…

    # March 19, 2013 at 5:38 pm

    You Rock CrocoDillon! lol Thanks soo much! Now, I just need to figure out the active navigation link part…

    # March 19, 2013 at 5:53 pm

    You’re welcome, glad it finally works :)

    Something like:

  • >Portfolio
  • could work.

# March 19, 2013 at 6:01 pm

That throws off a crap load of parsing errors… :(

# March 19, 2013 at 6:02 pm

< ?php
if (!isset($_GET))
$page = ‘home’;
$page = $_GET;
switch ($page) {

case “portfolio”:

case “resume”:

case “about”:

case “contact”:

case “home”:

// Default Page


You have access to the “$page” variable to test for which page is active in your nav menu. Of course, you could just use “$_GET” each time, but it’s less tidy.

# March 19, 2013 at 6:08 pm

Should be able to use jQuery to set Active Navigation, but so far everything I try is only highlighting the ‘home’ link.

# March 19, 2013 at 6:09 pm

Could you post your code?

# March 19, 2013 at 6:10 pm

For the parse errors I’d need to see the whole file where you create the menu.

Nice catch about the $page variable Ben :)

# March 19, 2013 at 6:10 pm

I have tried what is shown here:

However, in my case it is not working…

# March 19, 2013 at 6:11 pm

The menu is simply this in html:

# March 19, 2013 at 6:12 pm

Chris used to have something on here showing a way to do this with jQuery by link id, but I can’t find the shit.

# March 19, 2013 at 6:13 pm

Because you don’t have the / that’s in the jQuery selector. I’d prefer a php solution over a js one though.

# March 19, 2013 at 6:13 pm

I found his version before and modified it and it worked, but I lost all my files due to a electrical crash of my backup server…

Viewing 15 posts - 31 through 45 (of 70 total)

You must be logged in to reply to this topic.

There's a whole bunch of content on CSS-Tricks.

Search for Stuff   •   Browse the Archives

Get the Newsletter ... or get the RSS feed