Reputation: 3183
I have a 2 fold problem with doing 301 redirect. The old CMS I had on the domain is not being used and I am trying to figure out how to properly redirect if something matches.
1) Remove the query strings from the url and do a redirect. Here are the urls search engines trying to access which should redirect to the main page index.php
Example: http://www.mysite.com/?dispatch=products.search&features_hash=P2
Target: http://www.mysite.com/
OR
Example: http://www.mysite.com/index.php?dispatch=products.search&features_hash=V9
Target: http://www.mysite.com/
OR
Example: http://www.mysite.com/index.php?dispatch=news.list
Target: http://www.mysite.com/
Here is the code I tried so far which doesn't work:
RewriteCond %{QUERY_STRING} ^dispatch$
RewriteRule ^(.*)$ http://www.mysite.com/$1? [R=301,L]
2) The other problem I have is for some reason my site has duplicates in search engines via url= parameter. For example,
Example: http://www.mysite.com/?url=http://www.mysite.com
Target: http://www.mysite.com/
Basically they are same pages but when you take into account that I have category pages and other individual pages all being access by url= then its not right. Basically what I want to do is return 301 to the main mysite.com For this I tried the following code which doesn't work either:
RewriteCond %{QUERY_STRING} ^url$
RewriteRule ^(.*)index.php$ http://www.mysite.com/$1? [R=301,L]
*****------EDITED:------******* Complete htaccess file:
Options -Indexes
Options +SymLinksIfOwnerMatch
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^mysite.com
RewriteRule (.*) http://www.mysite.com/$1 [R=301,L]
RewriteRule ^([a-z0-9/-]+)-p-([0-9]+).html$ my-pages.php [NC,L,QSA]
</IfModule>
RewriteCond %{QUERY_STRING} base64_encode.*\(.*\) [OR]
RewriteCond %{QUERY_STRING} (\<|%3C).*script.*(\>|%3E) [NC,OR]
RewriteCond %{QUERY_STRING} (\<|%3C).*iframe.*(\>|%3E) [NC,OR]
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
RewriteCond %{QUERY_STRING} (;|'|"|%22).*(union|select|insert|drop|update|md5|benchmark|or|and|if).* [NC]
RewriteCond %{QUERY_STRING} ^(.*)/self/(.*)$ [NC]
RewriteCond %{QUERY_STRING} mosConfig_[a-zA-Z_]{1,21}(=|\%3D) [OR]
RewriteRule ^(.*)$ error_page.php [F,L]
RewriteCond %{REQUEST_METHOD} ^(TRACE|TRACK)
RewriteRule .* - [F]
ErrorDocument 400 /error_page.php?error_id=400
ErrorDocument 401 /error_page.php?error_id=401
ErrorDocument 403 /error_page.php?error_id=403
ErrorDocument 404 /error_page.php?error_id=404
ErrorDocument 405 /error_page.php?error_id=405
ErrorDocument 408 /error_page.php?error_id=408
ErrorDocument 415 /error_page.php?error_id=415
ErrorDocument 500 /error_page.php?error_id=500
ErrorDocument 501 /error_page.php?error_id=501
ErrorDocument 502 /error_page.php?error_id=502
ErrorDocument 503 /error_page.php?error_id=503
ErrorDocument 505 /error_page.php?error_id=505
ErrorDocument 504 /error_page.php?error_id=504
<FilesMatch "\.(inc|tpl|h|ihtml|sql|ini|conf|class|bin|spd|theme|module|exe)$">
deny from all
</FilesMatch>
<Files ~ "^\.ht">
Order allow,deny
Deny from all
Satisfy All
</Files>
SetEnvIfNoCase User-Agent "^libwww-perl*" block_bad_bots
Deny from env=block_bad_bots
RewriteCond %{HTTP_USER_AGENT} libwww-perl [OR]
RewriteCond %{QUERY_STRING} tool25 [OR]
RewriteCond %{QUERY_STRING} cmd.txt [OR]
RewriteCond %{QUERY_STRING} cmd.gif [OR]
RewriteCond %{QUERY_STRING} r57shell [OR]
RewriteCond %{QUERY_STRING} c99 [OR]
<Files 403.shtml>
order allow,deny
allow from all
</Files>
Upvotes: 0
Views: 248
Reputation: 8240
Try this
RewriteCond %{QUERY_STRING} ^dispatch
RewriteRule ^(.*)$ / [R=301,L]
RewriteCond %{QUERY_STRING} ^index.php\?dispatch
RewriteRule ^(.*)$ / [R=301,L]
RewriteCond %{QUERY_STRING} ^url=http://www.mysite.com
RewriteRule ^(.*)$ / [R=301,L]
Upvotes: 2