Jump to content
Larry Ullman's Book Forums
Sign in to follow this  

How Does Dynamic Routing Work In Php?

Recommended Posts

There is something about php that I have trouble understand coming from using javascript like angular. How does routing in php work exactly?  Like how does a php site know about going to a link 

(/browse/coffee/Dark+Roast/2) or a shop/product link. How does the htacess file works with the site. Currently, when going to a link the /shop/coffee, it responds by not found. I tried to look it up but I don't understand it per say as it different from the way I normally do it in javascript.

<body id="page1">
   <!-- header -->
   <div id="header">
      <div class="container">
         <div class="wrapper">
            <ul class="top-links">
               <li><a href="/index.php" class="first"><img alt="" src="/images/icon-home.gif" /></a></li>
               <li><a href="/cart.php"><img alt="" src="/images/icon-cart.gif" /></a></li>
               <li><a href="/contact.php"><img alt="" src="/images/icon-mail.gif" /></a></li>
               <li><a href="/sitemap.php"><img alt="" src="/images/icon-map.gif" /></a></li>
            <div class="logo">
               <h1><a href="/index.php">Coffee</a><span>Wouldn't you love a cup right now?</span></h1>
            <ul class="nav">
            <!-- MENU -->
            <li><a href="/shop/coffee/">Coffee</a></li>
            <li><a href="/shop/goodies/">Goodies</a></li>
            <li><a href="/shop/sales/">Sales</a></li>
            <li><a href="/wishlist.php">Wish List</a></li>
            <li><a href="/cart.php">Cart</a></li>
            <!-- END MENU -->
   <!-- content -->
   <div id="content">
      <div class="container">
         <div class="inside">

Share this post

Link to post
Share on other sites

Good question! This isn't a PHP thing, though, it's an Apache thing (the web server). The specific tool involved here is mod_rewrite. I'm pretty sure it's explained in the book but you can also search online for it. 

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Create New...