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';
else
$page = $_GET;
switch ($page) {

case “portfolio”:
include(‘theme/default/pages/portfolio.php’);
break;

case “resume”:
include(‘theme/default/pages/resume.php’);
break;

case “about”:
include(‘theme/default/pages/about.php’);
break;

case “contact”:
include(‘theme/default/pages/contact.php’);
break;

case “home”:
include(‘theme/default/pages/home.php’);
break;

// Default Page
default:
include(‘theme/default/pages/home.php’);
break;
}

?>

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:

http://css-tricks.com/snippets/jquery/add-active-navigation-class-based-on-url/

However, in my case it is not working…

# March 19, 2013 at 6:11 pm

The menu is simply this in html:

http://pastebin.com/gB2uHSDH

# 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.

*May or may not contain any actual "CSS" or "Tricks".