homepage Welcome to WebmasterWorld Guest from 54.205.144.54
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
htaccess redirect with ? in url
redirect htaccess
ads112001




msg:4209492
 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

 

BradleyT




msg:4209508
 6:47 pm on Sep 30, 2010 (gmt 0)


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.

ads112001




msg:4209526
 7:14 pm on Sep 30, 2010 (gmt 0)

yess thank you so much for your help that did it!

ads112001




msg:4209527
 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




msg:4209655
 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




msg:4209666
 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.

Jim

ads112001




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

thank you all for your help! much appreciated

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved