Can some provide input please

Discussion in 'Apache' started by Mike1958, Mar 15, 2007.

  1. #1
    I'm attempting to rewite URL's like this:

    http://www.domain.com/gourmet/cookbook/appetizer-20.html

    to look like this:

    http://www.domain.com/gourmet/cookbook/viewrecipes.php?page=20&category=appetizer

    The .httacess file is located in the /gourmet/cookbook/ directory and looks like this:

    Options +FollowSymLinks

    ReWriteEngine on
    RewriteRule ^gourmet/cookbook/([a-z]+)-([0-9]+)\.html$ /gourmet/cookbook/viewrecipes\.php?page=$2&category=$1 [L]

    I've also tried other variations of the rule:

    RewriteRule ^([a-z]+)-([0-9]+)\.html$ /gourmet/cookbook/viewrecipes\.php?page=$2&category=$1 [L]

    and

    RewriteRule ^([a-z]+)-([0-9]+)\.html$ viewrecipes\.php?page=$2&category=$1 [L]


    Still not working. Can anyone suggest a tweak? Also, are there any directives that will allow me to see the rewritten URL? That might make it easier to figure out.

    Thanks
    Mike
     
    Mike1958, Mar 15, 2007 IP
  2. rodney88

    rodney88 Guest

    Messages:
    480
    Likes Received:
    37
    Best Answers:
    0
    Trophy Points:
    0
    #2
    The last one looks like your best option. The only problem I can see is the \ in viewrecipes\.php

    The rewrite destination cannot contain any regex for obvious reasons and as such the period has no special meaning that would need escaping. Other than that, looks fine.

    You can add a R flag to the rule so that it'll send a location header and update your address bar, rather than a transparent rewrite on the server side.
     
    rodney88, Mar 15, 2007 IP