Forum Moderators: phranque
http://www.example.com/target/page.htm?V=3&from=widget
Today, there are still visits of Googlebot with such parameter strings.
So I want something in my .htaccess to cut away all behind "?" or "&" or "#" and to redirect to the URL without the parameter string.
For example, to process .htm files only:
RewriteCond %{QUERY_STRING} .
RewriteRule ^([^.]+)[b]\.htm[/b]$ http://www.example.com/$1[b].htm[/b]? [R=301,L]
Or to process only the single page.htm file:
RewriteCond %{QUERY_STRING} .
RewriteRule ^[b]page\.htm[/b]$ http://www.example.com/$[b]page.htm[/b]? [R=301,L]
In fact, if any other pages on your site still use query strings, you will have to use a specific pattern to avoid stripping their query strings.
Jim
RewriteCond %{QUERY_STRING} ^B= [NC,OR]
RewriteCond %{QUERY_STRING} ^D= [NC,OR]
RewriteCond %{QUERY_STRING} ^N= [NC,OR]
RewriteCond %{QUERY_STRING} ^M= [NC,OR]
RewriteCond %{QUERY_STRING} ^S= [NC,OR]
RewriteCond %{QUERY_STRING} ^V= [NC,OR]
RewriteCond %{QUERY_STRING} ^i_mpg= [NC]
RewriteRule (.*) http://example.com/$1? [R=301,L]
But I can not figure out the Syntax of .htaccess
Instead of the list of forbidden string, I would like to allow only ond type of query string containing "domains=".
Something what would be in Perl
if ( index ( $QUERY_STRING ), "domains=" ) < 0 ) { cut away query sting and make 301 redirect }
# IF query string contains one or more characters
RewriteCond %{QUERY_STRING} .
# and IF query string does NOT contain "domains="
RewriteCond %{QUERY_STRING} !domains=
# THEN redirect to remove query string
RewriteRule (.*) http://example.com/$1? [R=301,L]
This is largely a discussion forum, so please review the code above character-by-character, checking against the mod_rewrite documentation cited in our forum charter [webmasterworld.com]. The tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com] may also be helpful.
Specific questions about the code are welcome.
Jim