Mod_Rewrite 301 redirect not working

Discussion in 'Apache' started by millworx, Nov 22, 2008.

  1. #1
    So I created a sitemap and submitted it to google, problem is I messed up on one of the variables.

    Instead of it saying services= it said service= so the pages all got indexed but its all messed up. I am trying to 301 mod rewrite the messed up URLs to the correct ones.

    I have written it like so


    RewriteRule ^services.php?st=(.*)&city=(.*)&service=(.*)$ services.php?st=$1&city=$2&services=$3 [R=301,L]
    
    Code (markup):
    However it is not redirecting! Am I doing something wrong?
     
    millworx, Nov 22, 2008 IP
  2. joebert

    joebert Well-Known Member

    Messages:
    2,150
    Likes Received:
    88
    Best Answers:
    0
    Trophy Points:
    145
    #2
    RewriteRule doesn't apply the match to the querystring. You need to use RewriteCond for that.

    RewriteCond %{QUERY_STRING} ^st=([^&]+)&city=([^&]+)&service=([^&])$
    RewriteRule services\.php$ services.php?st=%1&city=%2&services=%3 [R=301]
    Code (markup):
    Note that when using RewriteCond back-references, you use %N instead of $N.
     
    joebert, Nov 22, 2008 IP