htaccess permanent redirect

RewriteEngine On

RewriteRule ^old-url/$ /new-url [R=permanent,L]

R=permanent : Permanent redirect

L : last rule, do not perform other rules after this one

 

Redirect with condition on query string

RewriteEngine On

RewriteCond %{QUERY_STRING} ^categ=4
RewriteRule ^index\.php /resurse/? [R=permanent,L]

Redirect url keeping the query string

http://www.simonecarletti.com/blog/2009/01/apache-query-string-redirects/

RewriteEngine On

RewriteCond %{REQUEST_URI}  ^/old-url\.php$
RewriteCond %{QUERY_STRING} ^id=([0-9]*)$
RewriteRule ^(.*)$ /new-url.php?id=%1 [R=permanent,L]

Or redirect to another domain

RewriteEngine On

RewriteCond %{QUERY_STRING} ^id=([0-9]*)$
RewriteRule ^page\.php$ http://mydomain.com/page/%1.pdf [R=301,L]

R=301 permanent redirect