Welcome to WebmasterWorld Guest from 54.205.75.60

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

htaccess redirect with ? in url

redirect htaccess

   
6:23 pm on Sep 30, 2010 (gmt 0)



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.

Right now in the .htaccess i'm using
Redirect /link?tw=ms http://www.website.com/index.php?offer=offer1
6:47 pm on Sep 30, 2010 (gmt 0)

10+ Year Member




RewriteEngine On
RewriteCond %{REQUEST_URI} /link
RewriteCond %{QUERY_STRING} ^fb=ms$
RewriteRule ^(.*) http://www.example.com/index.php?offer=offer1? [R=301,L]


When the URI is /link and the query string is fb=ms send them to /index.php?offer=offer1.
7:14 pm on Sep 30, 2010 (gmt 0)



yess thank you so much for your help that did it!
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]
12:10 am on Oct 1, 2010 (gmt 0)

10+ Year Member



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" :-) )
12:27 am on Oct 1, 2010 (gmt 0)

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member



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.

Jim
1:17 pm on Oct 1, 2010 (gmt 0)



thank you all for your help! much appreciated