Complex mod_rewrite syntax

Discussion in 'Apache' started by Senesoft, Nov 7, 2010.

  1. #1
    Hi all, the is my first post here. I'm having a heck of a time figuring out more complicated apache mod_rewrite syntax.

    Here's my original URL
    http://www.site1.com/forums/script.php?123-plus-extra

    I want to re-write this to:
    http://www.site2.com/forums/script.php?123-plus-extra

    and I want to match on "script.php" and the "123" portion of the query_string.

    Note, that I must match the query string also as there is some content on the original site that I DO NOT want to rewrite.

    I can match on the 123 no problem with the following syntax and it redirects:

    RewriteCond %{QUERY_STRING} ^123-(.*)$
    RewriteRule ^(.*)$ http://www.site2.com/$1 [L,R=301]


    I tried adding another RewriteCond command above the first with ^script.php, as well as ^script\.php (just in case I needed to escape the period. I also tried using {REQUEST_URI} to try and match script.php. But no matter what I try, it does nothing as soon as I add the second pattern.

    Any help is greatly appreciated.

    Thanks,

    ErnestA
     
    Senesoft, Nov 7, 2010 IP