HTACCESS Tricks & Tips
Rewrite rule to redirect http://www.domain.com to http://domain.com on Apache server by editing .htaccess file.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.domain\.com$ [NC]
RewriteRule ^(.*)$ http://domain.com/$1 [R=301,L]
OR
Rewrite rule to redirect http://domain.com to http://www.domain.com
RewriteEngine on
rewritecond %{http_host} ^domain.com [nc]
rewriterule ^(.*)$ http://www.domain.com/$1 [r=301,nc]
You need to REPLACE domain.com and www.domain.com with your actual domain name.
How to Redirec Subdirectories to the Root Directory with HTAccess
Redirect directory
RedirectMatch 301 ^/example/$ http://root-domain.com/
Redirect the example directory and all other files and sub-directories as well.
RedirectMatch 301 ^/example/.*$ http://root-domain.com/
Redirect your old domain to new domain
Assuming your website overall site structure hasn’t been changed and you just want to relocated the site to the new domain, in order to do this you can add the following lines to your .htaccess file located at the root of your old domain:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^olddomain.com.au$ [OR]
RewriteCond %{HTTP_HOST} ^www.olddomain.com.au$
RewriteRule (.*)$ http://newdomain.com.au/$1 [R=301,L]
Redirect all the website visitors to a single specific page:
RewriteEngine On
RewriteCond %{REQUEST_URI} !=/landingpage.html
RewriteRule ^ /landingpage.html [R=301]

