.htacces Redirects

Most of the below culled from stupid .htaccess tricks

Rewrite URL to always include the www and redirect multiple doamins to one


###### always access from www and redirect multiple doamins to one

rewriteCond %{http_host} ^domain\.com$ [OR]
rewriteCond %{http_host} ^domain\.org$ [OR]
rewriteCond %{http_host} ^www\.domain\.org$ [OR]
rewriteCond %{http_host} ^subdomain\.domain\.org$ [OR]
rewriteCond %{http_host} ^www\.subdomain\.domain\.org$ [NC]
rewriteRule ^(.*)$ http://www.domain.com/$1 [r=301,L]

Aways remove the www


###### redirect to non-www

rewriteCond %{http_host} ^www\.domain\.com$ [NC]
rewriteRule ^(.*)$ http://domain.com/$1 [r=301,L]

Redirect old files and folders to new


###### this assumes that you're on the same domain

Redirect permanent /old-page.html http://www.domain.com/new-page.html
Redirect permanent /old-folder/page.html http://www.domain.com/new-folder/new-page.html
Redirect permanent /old-folder/1/page.html http://www.domain.com/new-folder/2/page.html

Redirect permanent /old-folder/ http://www.domain.com/new-folder/

Snippets and tagged