Jump to content
Larry Ullman's Book Forums

Menu Will Not Access Content.


Recommended Posts

I have read the book!, but the Mod_rewrite statements will not access the menu items.  I have tried all the suggestions in the book.  I am trying to use this book in a university course and regret my decision.  Could you please send me a working site and the code that really does work?

 

 

Link to comment
Share on other sites

Here is the code in the .htaccess

 

# Disable directory browsing:
Options All -Indexes  
# Prevent folder listing:
IndexIgnore *  
# Prevent access to any file:
<FilesMatch "^.*$">
Order Allow,Deny  
Deny from all
</FilesMatch>

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /ex2/
# For sales:
RewriteRule ^shop/sales/?$ sales.php
# For the primary categories:
RewriteRule ^shop/([A-Za-z\+]+)/?$ shop.php?type=$1
# For specific products:
RewriteRule ^browse/([A-Za-z\+\-]+)/([A-Za-z\+\-]+)/([0-9]+)$ browse.php?type=$1&category=$2&id=$3
# For HTTPS pages:
RewriteCond %{HTTPS} off
RewriteRule ^(checkout\.php|billing\.php|final\.php|admin/(.*))$ https://%{HTTP_HOST}/$1 [R=301,L]
</IfModule>

 

This file is located in the includes folder

 

Here are the menu items

 

      <ul class="nav">
            <!-- MENU -->
            <li><a href="./shop/coffee">Coffee</a></li>
        <!--    <li><a href="/shop/coffee/">Coffee</a></li> -->
            <li><a href="./shop/shop.php">Goodies</a></li>
            <li><a href="./sales.php">Sales</a></li>
            <li><a href="./wishlist.php">Wish List</a></li>
            <li><a href="./cart.php">Cart</a></li>
            <!-- END MENU -->
            </ul>

 

The first three will not access the pages and the last three, I simply put the reference to the correct file and they will bring up the page but it still has errors.  That's because there is so much redirections that the program seems to be confused.

 

 

 

 

Link to comment
Share on other sites

The first three will not work because your regex is too strict.

According to your regex, after /shop, you have to have another /, but none of your links do, thus they will not work.

As a side note, your second rewrite rule completely trumps your first rewrite rule, making it pointless.

 

As for the last three, I cannot comment on the errors without seeing the related code in the scripts themselves, but likely, you are accessing them without all the proper information.

 

Just to reassure you though, mod_rewrite is a tricky beast and takes some practice.

I got quite annoyed at it myself before I finally got it down. Keep at it, and you'll be okay.

  • Upvote 1
Link to comment
Share on other sites

 Share

×
×
  • Create New...