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 &?


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:

if ( strpos($_SERVER['REQUEST_URI'],'&') ) {
	header('Location: http://localhost' . str_replace('&','&',$_SERVER['REQUEST_URI']));

Which works, and Google can now track the source/medium/campaign of inbound links.


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).