htaccess permanent redirect

Redirect permanent /old-url.html


Redirect 301 /old-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

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$ [R=301,L]

R=301 permanent redirect

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

RewriteCond %{HTTP_HOST} ^(www\.)?$
RewriteRule (.*)$$1 [R=301,L]