Forum Moderators: phranque
----------------------
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.co\.uk [NC]
RewriteRule (.*) http://www.example.co.uk/$1 [R=301,L]
RewriteRule ^index.php$ http://www.example.co.uk/ [R=301,L]
Redirect 301 /index.php?cat=7 http://www.example.co.uk/?cat=7
----------------------
The second rule will create an 'infinite' loop if index.php is defined as the DirectoryIndex file. While it may eventually give you the result you want, there will likely be eight to ten redirects in a row every time "index.php" is requested by a client.
Your last directive won't work, because mod_alias isn't aware of query strings, and can take no action based on them. The good news is that your second rule would handle that case as-is, so this third directive isn't needed. However, I'll show a commented-out example of how you might handle the query string if you needed to change the category from 7 to 8. Note that since it is a more specific rule than that derived from your original second rule, this example rule would need to be placed ahead of the original second rule as shown in order to have the desired effect.
Modified code:
RewriteEngine onRewriteCond %{HTTP_HOST} ^www\.example\.co\.uk [NC]
RewriteRule (.*) http://example.co.uk/$1 [R=301,L]
# Commented-out -- example only; Change cat from 7 to 8 for "index.php" or "/" page requests
# RewriteCond %{QUERY_STRING} ^cat=7$
# RewriteRule ^(index\.php)?$ http://example.co.uk/?cat=8 [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php
RewriteRule ^index\.php$ http://example.co.uk/ [R=301,L]