homepage Welcome to WebmasterWorld Guest from 54.166.110.222
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
Facebook Query String.
301 duplicate homepage URL
Pass the Dutchie




msg:4181736
 11:49 am on Aug 4, 2010 (gmt 0)

We have the FB fan/like thinggy on our site and I noticed today that in WMT that a page with http://www.example.com/?_fb_q=1 is now a duplicate of our home page ("Google found the keyword widgets on these top pages:")

All I know is that this is something to do with Facebook and this URL is duplicating our home page. Gotta get its fixed.

I have tried the following 301 but I get 500 server error and would really appreciate any advice /syntax correction.

JDM, I found this on WebmasterWorld and tried to modify it ; ))

RewriteCond %{QUERY_STRING} ^q=.
RewriteRule ^search\.php$ http://www.example.com/search.html [R=301,L]

too:

RewriteCond %{QUERY_STRING} ^?_fb_q=.
RewriteRule ^?_fb_q=1$ http://www.example.com [R=301,L]

Thanks guys

 

jdMorgan




msg:4181788
 1:36 pm on Aug 4, 2010 (gmt 0)

The pattern in the RewriteCond must match the query string only. The query string does not *start* with a question mark... That is, the question mark is not "included" in the query string, nor is it included in the URL-path -- It is a delimiter *between* these fields and part of neither. Compare my example pattern with yours...

The pattern in the RewriteRule must match the requested local URL-path only. It must not contain the protocol, hostname, or query string. If the requested URL-path is just "/", then the RewriteRule pattern should be "^$" (the leading slash is stripped in .htaccess).

Jim

Pass the Dutchie




msg:4181794
 1:57 pm on Aug 4, 2010 (gmt 0)

Thanks Jim,

I have tried the following but as it does not redirect the URL from http://www.example.com/?_fb_q=1 to http://www.example.com/ I assume I have missunderstood your instructions.

This is what I have:

RewriteCond %{QUERY_STRING} ^q=.
RewriteRule ^$ http://www.example.com [R=301,L]

I dont want to redirect all query strings to the home page just ?_fb_q=1

Thanks again.

g1smd




msg:4181814
 2:25 pm on Aug 4, 2010 (gmt 0)

Add a question mark to the end of the target URL to clear the appended query string.

Redirect for query string on both / and /index.php requests.

Redirect to root with trailing slash included.


RewriteCond %{QUERY_STRING} &?_fb_q=
RewriteRule ^(index\.php)?$ http://www.example.com/? [R=301,L]

Pass the Dutchie




msg:4181830
 2:51 pm on Aug 4, 2010 (gmt 0)

I would never have gotten that but I think I now understand.

thanks Jim.

jdMorgan




msg:4181858
 3:26 pm on Aug 4, 2010 (gmt 0)

If you only want to redirect queries starting with "_fb_q=" then use

RewriteCond %{QUERY_STRING} ^_fb_q=
RewriteRule ^(index\.php)?$ http://www.example.com/? [R=301,L]

If you want to redirect queries *containing* "_fb_q=" (possibly among other query name/value pairs), then use

RewriteCond %{QUERY_STRING} ^([^&]+&)*_fb_q=
RewriteRule ^(index\.php)?$ http://www.example.com/? [R=301,L]

This avoids a potential ambiguity in the use of a pattern such as "&?_fb_q=", which can match either
"<anything or nothing>_fb_q=" or "<anything or nothing>&_fb_q=".

Note that in all three of these patterns in this post, the "?" is not a literal. It is a regular-expressions quantifier meaning "Match zero or one of the preceding character." If you ever want to match a literal question mark character, then it must be escaped, as in "\?".

The question mark at the end of the RewriteRule substitution (which is not a regex pattern) is a different operator meaning "Replace the current query string with the query string that follows," which in this case, is blank.

Jim

Pass the Dutchie




msg:4181893
 4:07 pm on Aug 4, 2010 (gmt 0)

I just realised there is a clash with the following line in the htaccess file

RewriteRule ^index\.(php|html|htm) http://www.example.com/ [R=301,L]

I guess its stuck in a loop. Can these two rules coexist?

jdMorgan




msg:4182058
 8:10 pm on Aug 4, 2010 (gmt 0)

That newly-mentioned rule would be more robustly written as:

RewriteCond %{THE_REQUEST} ^[A-Z]+\ /index\.(php|html?)\ HTTP/
RewriteRule ^index\.(php|html?)$ http://www.example.com/ [R=301,L]

However, there should be no clash, because neither of these rules redirects to "index.php"

Jim

Pass the Dutchie




msg:4182066
 8:27 pm on Aug 4, 2010 (gmt 0)

Jim,

After a serious session of head scratching, trial and error your explanation has starting to sink in.

Based on your improved version I have managed to get these two rules to coexist with an additional RewriteCond and slight mod:

RewriteCond %{QUERY_STRING} ^([^&]+&)*_fb_q=
RewriteRule ^(index\.htm)?$ http://www.example.com/? [R=301,L]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.php\ HTTP/
RewriteRule ^(([^/]+/)*)index\.php$ http://www.example.com/$1 [R=301,L]


Its basically a hack of a previous posts of yours but its actually works!

Note: I switched php to htm in first RewriteRule. (My server returns a 401 for /index.htm which is not ideal but better than a duplicate page).

Not very pretty I know but seems to do the job :)

you mentioned here: [webmasterworld.com...]

You do need a rewritecond to prevent an infinite loop if DirectoryIndex is set (as is customary) to include index.php.


Perhaps this would be a better solution but I could not figure out where to place the rewritecond.

As always, much appreciated.

Pass the Dutchie




msg:4182068
 8:34 pm on Aug 4, 2010 (gmt 0)

looks like we posted same time!

As expected your solution is nicer :)

RewriteCond %{QUERY_STRING} ^([^&]+&)*_fb_q=
RewriteRule ^(index\.php)?$ http://www.example.com/? [R=301,L]

RewriteCond %{THE_REQUEST} ^[A-Z]+\ /index\.(php|html?)\ HTTP/
RewriteRule ^index\.(php|html?)$ http://www.example.com/ [R=301,L]


Works a charm. Your a star!

thanks Jim

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