htaccess permanent redirect

Redirect permanent /old-url.html http://www.example.com/new-url.html

or

Redirect 301 /old-url.html http://www.example.com/new-url.html

with or without absolute paths

Redirect 301 /old-url.html /new-url.html

Using mod rewrite

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

Redirect an entire domain to another one keeping the url's

RewriteCond %{HTTP_HOST} ^(www\.)?old-domain.com$
RewriteRule (.*)$ http://www.new-domain.com/$1 [R=301,L]