How to redirect from to

HTACCESS Tricks & Tips

Rewrite rule to redirect to on Apache server by editing .htaccess file.

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.domain\.com$ [NC]
RewriteRule ^(.*)$$1 [R=301,L]


Rewrite rule to redirect to

RewriteEngine on
rewritecond %{http_host} ^ [nc]
rewriterule ^(.*)$$1 [r=301,nc]

Redirecting a sub-domain e.g:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.domain\.com\.au$ [NC]
RewriteRule ^(.*)$$1 [R=301,L]


RewriteEngine On
RewriteCond %{HTTP_HOST} ^ [NC]
RewriteRule ^(.*)$$1 [R=301,L]

You need to REPLACE and with your actual domain name.

How to Redirec Subdirectories to the Root Directory with HTAccess

Redirect directory

RedirectMatch 301 ^/example/$

Redirect the example directory and all other files and sub-directories as well.

RedirectMatch 301 ^/example/.*$

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} ^$ [OR]
RewriteCond %{HTTP_HOST} ^$
RewriteRule (.*)$$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]

Leave a Reply

Your email address will not be published. Required fields are marked *