SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2008
    Posts
    34
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Mod rewrite to replace & with &

    Hi All,

    I've got some inbound links on external sites that I need to track (using UTM source/medium/campaign on Google Analytics). I've entered the links using & on the site in question but when the URLs are output they're changed to &. The visitor gets to the content but Analytics doesn't track the source/etc.

    Is there a way to use mod rewrite in the .htaccess file to replace & with &?

    Cheers,
    Richard.

  2. #2
    SitePoint Enthusiast
    Join Date
    Oct 2008
    Posts
    34
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Actually the more I look at this, I don't think that this can be done with mod rewrite.

    I'm using Wordpress so I just put the following in the functions.php file:

    Code:
    if ( strpos($_SERVER['REQUEST_URI'],'&') ) {
    	header('Location: http://localhost' . str_replace('&','&',$_SERVER['REQUEST_URI']));
    	exit;
    }
    Which works, and Google can now track the source/medium/campaign of inbound links.

  3. #3
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,653
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    Franny,

    According to Uniform Resource Identifiers (URI): Generic Syntax, & is a reserved character (which may only be used in a query string). IMHO, you'd be best to make the & to & conversion within the receiving script (before accessing the database).

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •