Mod rewrite for multiple files

Discussion in 'Apache' started by greatlogix, Sep 14, 2007.

  1. #1
    I am using following rewrite rule for some pages of my shopping cart site.
    At the moment it works for seo_page.php?id=value only. Whenever i try to access special_offer.php?id=value it does not work and apache apply only first rule that is for seo_page.php. I want to add rules for at least 5 files. Is it possible.
     
    greatlogix, Sep 14, 2007 IP
  2. evera

    evera Peon

    Messages:
    283
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I think you can't do it like in your example.
    RewriteRule ^(.*).html$ /seo_page.php?cn=$1 could give /1.html
    RewriteRule ^(.*).html$ /special_offer.php?cn=$1 could give /1.html

    so the sites are not unique...

    you should try something like this:

    RewriteEngine on 
    RewriteRule ^(.*)_([0-9]+)\.html$ http://www.domain.com/$1.php?cn=$2
    
    Code (markup):
    This should give out this:
    seo_page_1.html
    special_offer_1.html

    (not tested)
     
    evera, Sep 14, 2007 IP
  3. greatlogix

    greatlogix Active Member

    Messages:
    664
    Likes Received:
    13
    Best Answers:
    1
    Trophy Points:
    85
    #3
    Thanks for help.
    I don't want 'special_offer' in url. Instead of passing IDs in url (1,2,3...) I want to send keywords in url so request to site.com/special_offer.php?id=crib should be like site.com/crib.html.
     
    greatlogix, Sep 14, 2007 IP
  4. evera

    evera Peon

    Messages:
    283
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #4
    
    RewriteRule ^(.*).html$ /seo_page.php?cn=$1 [L]
    RewriteRule ^(.*).html$ /special_offer.php?cn=$1 [L]
    Code (markup):
    MAybe with an [L] flag at the end...
     
    evera, Sep 14, 2007 IP
  5. greatlogix

    greatlogix Active Member

    Messages:
    664
    Likes Received:
    13
    Best Answers:
    1
    Trophy Points:
    85
    #5
    No friend, It did not work. It is still going to seo_page.php. special_offer page's rewrite rule is not working.
     
    greatlogix, Sep 17, 2007 IP
  6. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #6
    You'll have to change the URL for one of the scripts. You can't give two scripts the exact same fake URLs. It's like trying to fit two gallons of milk in a gallon container. Only one will fit.
     
    Nintendo, Sep 17, 2007 IP