regex - Using htaccess to remove single query parameter -


For reasons that are not going here, Google listed one of my sites with an unnecessary query string The URL is being I would like to modify my HTACAC file in 301 which redirects all those requests without the URL to the unnecessary part of the string string without the URL, but maintains any other part of the query string that becomes part of that address (Or not) Make sure other functionality is retained.

For example, the following URL

  http://example.com/product.php?query=12345 http: // example com / index.php? Section = ABC 123 and query = 56789 http://example.com/search.php?query=987654&term=keyword  

will be

  Http://example.com/product.php http://example.com/index.php?section=ABC123 http://example.com/search.php?term=keyword  
< P> Effectively isolating 'query = xxxxx'? Or &, but make sure that other queries have been retained and will not work by removing the query = 98765 in the correct syntax (i.e., only the third example, because it is search.php and term = keyword Instead of search.php? Term = keyword).

Some other stack was viewing through replies and found:

  rewrite / rewritecode% {REQUEST_FILENAME}! -f Recycling% {REQUEST_FILENAME}! -dRevertCand% {QUERY_STRING} (. *)? & Amp ;; Query = [^ amp;] + & amp;? (. *)? [NC] RewityCand% {REQUEST_URI} /(.*) Rewritable. *% 3?% 1% 2? [R = 301, L]  

But this does not seem to work, and my knowledge of HTACAA and amp;

>

Try it out (I tested it with your examples and it is working fine):

  Revalidation Engine on Rev. Cindy% {QUERY_STRING} ^ (. * ) & Amp ;; Query = [^ & amp; ;] + & Amp ;? (? *) $ [Nc] rewritable ^ /? (. *) $ / $ 1?% 1% 2 [R = 301, L]  

In addition, you should add a rule to apply this rule only to existing files (Which is up to you).
If you want:

  RewriteCond% {REQUEST_FILENAME} at RewriteEngine rewrite% {QUERY_STRING} ^ (. *) & Amp ;; Query = [^ & amp;] + & amp;? (? *) $ [Nc] rewrite rule / / (? *) $ / $ 1?% 1% 2 [R = 301, L]  

Comments