links break with mod rewrite

Discussion in 'PHP' started by beermaker74, Feb 15, 2007.

  1. #1
    I have been developing this site and I have finally got around to doing the mod rewrite. i have a dynamic page www.myserver.com/listings.php?houseid=1. I have the rewrite now working with www.myserver.com/listings/1 I am more than happy with this address. The one thing I need to do is include the slash at the end of the url ie www.myserver.com/listings/1/ so that if they put this in the address bar that it directs them to www.myserver.com/listings/1. Since I am new at this rewriting I am not quite sure what is going on in the background. My issue is the links that I have on the page are all broken. But they work if I put absolute links. Is this what is required for it to work? Since it is only a few dynamic pages that I have to change it is no big deal but if i had 100 pages to change I would be a bit frustrated. So is there a way to deal with this. Maybe in the htaccess where my rewrite rules are?
    thanks
     
    beermaker74, Feb 15, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    You want to redirect the URLs with the slash at the end to the same URL without the slash?

    Try this.
    
    
    RedirectMatch 301 ^listings\/([\d]+)\/$ listings/$1
    
    Code (markup):
     
    nico_swd, Feb 15, 2007 IP