.htaccess help :-(

Discussion in 'Apache' started by tomupton, Apr 6, 2010.

  1. #1
    Hi Guy's,

    Im hoping someone can help me here....

    OK here is my .htaccess file

    Options +FollowSymLinks
    RewriteEngine On
    RewriteBase /

    RewriteRule ^([0-9]+)-(.+)\.php$ Boatcameras/news-details.php?news_id=$1&news_seolink=$2 [L]
    RewriteRule ^([0-9]+)\.php$ Boatcameras/product-range.php?ProdCat=$1 [L]
    RewriteRule ^([0-9]+)-(.+)\.php$ Boatcameras/product-details.php?ProdID=$1&ProdSeo=$2 [L]

    The first two rewrite rules are working perfectly, but for some reason the third rewriterule is returning the same pages as the first rewriterule. When obviously looking at this htaccess file, it should be going too product-details.php.

    Please could someone advise me on whats going wrong here? Im new to htaccess and Mod-Rewrite, and after spending 6hrs working on this last night im pretty exhausted!!

    Thanks in advance

    Tom
     
    tomupton, Apr 6, 2010 IP
  2. hans

    hans Well-Known Member

    Messages:
    2,923
    Likes Received:
    126
    Best Answers:
    1
    Trophy Points:
    173
    #2
    may be its just a syntax matter - the [L] at the end of your rule lines indicates Last rule - yet you add two more rules below ...
    I separate such multiple lines as below ( the 301 is needed to show Google and other SE that the new URL is a permanent redirect

    Options +Indexes
    Options +FollowSymlinks
    RewriteEngine on
    RewriteBase /
    RewriteRule ^([0-9]+)-(.+)\.php$ Boatcameras/news-details.php?news_id=$1&news_seolink=$2 [L,R=301]

    In my .htaccess - I have multiple sets as above for separate URL rewrites - in your case I would have 3 such sets ....

    and what about your $2 by the end of line 1 and 3 ... - you sure this is correct syntax for your case
     
    hans, Apr 6, 2010 IP
  3. tomupton

    tomupton Active Member

    Messages:
    392
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    58
    #3
    Thanks for your quick reply.

    someone in another forum mentioned this "There are 3 RewriteRules on your .htaccess files, but the 3rd one is completely useless as it has the same pattern as the first one, only the substitution changes, so that 3rd rewriterule is never reached"

    I have tried what you suggested above by adding [L,R=301] unfortunately this hasnt worked either.

    The strange thing is, these are 2 seperate pages im trying to redirect with different query strings and obviously urls within the .htaccess file. I just dont understand why this is not working correctly.

    The $2 corresponds too the "Seo link text" for example "1-Test-News-Item-1.php" this is what is being passed for the first Rewriterule. The first "1" is the item ID number, then the Text following the - is the seo text. This text relates too $2.

    Hope this makes sense! lol

    Regards

    Tom
     
    tomupton, Apr 6, 2010 IP
  4. tomupton

    tomupton Active Member

    Messages:
    392
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    58
    #4
    Ive managed to resolve this by adding the following to the 3rd RewriteRule

    Thanks for all your help though ;-)
     
    tomupton, Apr 6, 2010 IP