WEB Apache Rewrite Rule to add a URL Parameter?

Discussion in 'OT Technology' started by fishbulb, May 28, 2008.

  1. fishbulb

    fishbulb Active Member

    Joined:
    Oct 29, 2001
    Messages:
    6,848
    Likes Received:
    4
    Location:
    md
    my .htaccess file currently forwards an old domain to a new one and maintains the rest of the url string:

    Code:
    Options +FollowSymLinks
    RewriteEngine on
    RewriteRule (.*) http://mynewsite.com/$1 [R=301,L]
    
    So http://myoldsite.com/newthread.php?do=newthread&f=168
    forwards to http://mynewsite.com/newthread.php?do=newthread&f=168

    Is there anyway I can have the .htaccess file tack on a URL parameter to the end of that string?

    Code:
    So http://myoldsite.com/newthread.php?do=newthread&f=168
    forwards to http://mynewsite.com/newthread.php?do=newthread&f=168&src=myoldsite
    
    Thanks
     
  2. 96

    96 Merry Christmas :D

    Joined:
    Oct 30, 2001
    Messages:
    16,073
    Likes Received:
    0
    Location:
    San Diego
    this may work (untested and never done this type of rewrite before)

    Code:
    RewriteRule (.*) http://mynewsite.com/$1&src=myoldsite [R=301,L,QSA]
    
    Not sure how that will play if the oldsite.com URL doesn't have any parameters (it could turn into something like http://mynewsite.com/&src=myoldsite, which could error since it is a & instead of ? at the start)
     
  3. Josh

    Josh Guest

    You could also just set up a script to track hits from your old domain.

    the other option would be to do this...

    Options +FollowSymLinks
    RewriteEngine on
    RewriteRule (.*) http://mynewsite.com/referTrack.php?src=old&redirect=$1 [R=301,L]
    and set that page up to count the hit, then redirect to the page specified. If you are getting a request to redirect to pages with & signs it may fuck it up
     
  4. 96

    96 Merry Christmas :D

    Joined:
    Oct 30, 2001
    Messages:
    16,073
    Likes Received:
    0
    Location:
    San Diego
    :doh:

    of course, put src first.... it was a long day at work today :o
     

Share This Page