MOD Rewrite

Discussion in 'PHP' started by adamjblakey, Feb 13, 2008.

  1. #1
    Hi,

    I am trying to use mod rewrite to obtain SEO friendly url's.

    I have a list of items producing like this:

    entertainment-listings.php?cat=private-events&title=accounts-and-financing

    What i would like the results coming out like is:

    e.g. www.website.com/private-events/accounts-and-financing.php

    Can someone advise me please.

    Cheers,
    Adam
     
    adamjblakey, Feb 13, 2008 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    
    RewriteEngine On
    RewriteRule ^([\w-]+)/([\w-]+)\.php$ entertainment-listings.php?cat=$1&title=$2
    
    Code (markup):
     
    nico_swd, Feb 13, 2008 IP
  3. adamjblakey

    adamjblakey Active Member

    Messages:
    1,121
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    80
    #3
    Thanks a lot nico :)
     
    adamjblakey, Feb 13, 2008 IP
  4. adamjblakey

    adamjblakey Active Member

    Messages:
    1,121
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    80
    #4
    I have another issue with this that i cannot figure out:

    What i have done is i have links like this:
    <a href="{$domain}/corporate-events/{$result.subcategory|stripres}.html" title="Corporate Events - {$result.subcategory}" class="submenu">{$result.subcategory}</a>

    With the re-write rule:
    RewriteRule ^corporate-events/(.*)\.html$ entertainment-listings.php?title=$1

    This is working fine but what i want to do now is have the link like this:
    <a href="{$domain}/{$resultb.region|stripres}/{$cat}/{$pagename|stripres}.html" title="{$resultb.area} - {$resultb.region}" class="submenu">{$resultb.region}</a>

    What would the re-write be on this?

    Cheers,
    Adam
     
    adamjblakey, Feb 15, 2008 IP
  5. adamjblakey

    adamjblakey Active Member

    Messages:
    1,121
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    80
    #5
    Anyone help with this one, it is bugging me.
     
    adamjblakey, Feb 16, 2008 IP
  6. jayshah

    jayshah Peon

    Messages:
    1,126
    Likes Received:
    68
    Best Answers:
    1
    Trophy Points:
    0
    #6
    
    RewriteRule ^corporate-events/(.*)\.html$ entertainment-listings.php?title=$1
    
    Code (markup):
    The (.*) is greedy. Try (.*?)

    
    RewriteRule ^corporate-events/(.*?)\.html$ entertainment-listings.php?title=$1
    
    Code (markup):
    Jay
     
    jayshah, Feb 16, 2008 IP