Forum Moderators: phranque
RewriteCond %{QUERY_STRING} ^query-string-pattern$ RewriteCond %{THE_REQUEST} ^[A-Z]+\ /[i]url-path-pattern[/i]\?[i]query-string-pattern[/i](#[^\ ]*)?\ HTTP/
# 1 & 3. Redirect requests for /index.php in any directory
# to "/" in that same directory, removing any query string
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /([^/]+/)*index\.php([?#][^\ ]*)?\ HTTP/
RewriteRule ^(([^/]+/)*)index\.php$ http://www.example.com/$1? [R=301,L]
#
# 2. Redirect to remove query string from any directory-paths
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /([^/]+/)*\?[^\ ]*\ HTTP/
RewriteRule ^(([^/]+/)*)$ http://www.example.com/$1? [R=301,L]