Help with strange htaccess reweriterule behaviour

Discussion in 'Site & Server Administration' started by lbushby, Feb 28, 2012.

  1. #1
    First things first im new to the rewrite rule and this is my first application so might be something silly I have over looked but any thoughts or advice would be appreciated.

    I am applying a rewrite rule for people looking for car information. Its 3 level deep so the url can be

    www.sitename.com/model
    www.sitename.com/model/mark
    www.sitename.com/model/mark/year

    and the rewrite rule directed to the appropriate model.php, mark.php, year.php file

    In this example

    Make - Audi
    Model - A4
    Mark = 1.8 or 1.8 quattro etc
    Year = 2008 etc

    The rewrite rule is as follows in my htaccess file for Audi A4.

    RewriteRule a4/(.*)/(.*)$ /info/year.php?make=AUDI&model=a4&mark=$1&year=$2
    RewriteRule a4/(.*)$ /info/mark.php?make=AUDI&model=a4&mark=$1
    RewriteRule a4$ /info/model.php?make=AUDI&model=a4

    This is working fine other than one small problem that would appear to be caused by the word "quattro" and more specifically the letter "q"

    www.sitename.com/a4/1.6 I take me to the mark.php and displays the make,model, mark info on vehicle as desired.
    www.sitename.com/a4/2.5-d Same as above works great.

    however the following example redirect to the model.php not mark.php as expected

    www.sitename.com/a4/1.8-tfsi-quattro
    www.sitename.com/a4/1.8-quattro

    If I remove the "Q" from quattro as follows is directs correctly to mark.php

    www.sitename.com/a4/1.8-uattro

    Any thought or suggestion on this issue would be appreciated. Im a little stumped
     
    lbushby, Feb 28, 2012 IP
  2. lbushby

    lbushby Greenhorn

    Messages:
    37
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #2
    Problem resolved indirectly when I came across another problem relating to the rewriteule. Well I did say this was my first implimentation so no surprise I missed something out.

    Is used the syntax

    RewriteRule a4$ /info/model.php?make=AUDI&model=a4

    Audi also have a model of quattro so I also have an entry in for

    RewriteRule quattro$ /info/model.php?make=AUDI&model=a4

    this meant that any url ending with quattro was getting redirected to the model.php

    like www.sitename.com/a4/1.8-tfsi-quattro etc

    The fix was to apply the ^ symbol to the start of the required match.

    So all rewrites now look like

    RewriteRule ^quattro$ /info/model.php?make=AUDI&model=a4
    RewriteRule ^a4$ /info/model.php?make=AUDI&model=a4

    This removed any ambiguity in what the exact URL needing redirecting was as ^ represents the start of the URL after domain and $ the end

    All seems to be working now.

    Just posted fix in case it helped someone else with a similar problem
     
    lbushby, Mar 3, 2012 IP