Trying to redirect /link?fb=ms to /link.html Using this redirect so in google analytics i can do a search for fb=ms and track how many visitors are coming from facebook to the site.
When the URI is /link and the query string is fb=ms send them to /index.php?offer=offer1.
ads112001
7:14 pm on Sep 30, 2010 (gmt 0)
yess thank you so much for your help that did it!
ads112001
7:15 pm on Sep 30, 2010 (gmt 0)
quick question. If i wanted to do multiple redirects, do i have to repeat the code for each? i.e. i wanted to use ?fb=ms and ?tw=ms would i have to repeat this for each? RewriteEngine On RewriteCond %{REQUEST_URI} /link RewriteCond %{QUERY_STRING} ^fb=ms$ RewriteRule ^(.*) http://www.example.com/index.php?offer=offer1? [R=301,L]
sublime1
12:10 am on Oct 1, 2010 (gmt 0)
ads112001 -- in BradlyT's example, you could use a regular expresion in the second condition to generalize the pattern being matched, e.g.
RewriteCond ${QUERY_STRING} ^(fb|tw)=ms$
Mastery of regular expressions is worth the effort, and I have seen some people get really proficient with them in as little as five to ten years :-). Fortunately, there's google -- try "regex examples" or "regexp examples".
(Or, because Google itself has operators that work similarly to regexp, try "regex|regexp examples" :-) )
jdMorgan
12:27 am on Oct 1, 2010 (gmt 0)
A bit of optimization:
RewriteEngine on # RewriteCond %{QUERY_STRING} ^(fb|tw)=ms$ RewriteRule ^link$ http://www.example.com/?offer=offer1? [R=301,L]
Tip: Use
DirectoryIndex /index.php
(if not already configured) to map requests for the URL-path "/" to the filepath "/index.php", and do not mention "/index.php" in your on-page links or in redirects. It is unnecessary, wastes disk space and bandwidth, exposes your website technology, and will cause you to want to do a bunch of redirects if your site technology changes in the future. So linking to "/" is shorter, faster, safer, and will never need to change.