Permanent Redirection Rules in .htaccess File
Everlasting Redirection Guidelines in .htaccess File
We will set http redirection guidelines within the apache principal configuration file, however some case we wouldn’t have permission to edit default configuration file (e.g. shared host, cPanel server). On this case, they supply the .htaccess file which is an Apache internet server function to make configuration adjustments on a per-directory foundation. It lets you take directives that may usually be put in apache’s principal configuration information, and put them in a listing particular configuration file as an alternative. On this tutorial, we’ll focus on the right way to set everlasting redirection guidelines within the .htaccess file. There are a lot of sorts of http redirection guidelines:
301 Everlasting redirect.
302 Non permanent redirect.
Please learn our KB https://www.webhostingpeople.internet/ideas/kb/types-redirects-htaccess-redirect-tips-tricks/ for extra about http redirection varieties.
The 301 redirect is a everlasting redirection and is used to point to search engines like google that the originating URL has completely moved to new URL. That is the very best technique for implementing redirect on an internet site. It acts as essentially the most environment friendly and search engine pleasant technique for webpage redirection.
Now we’ll focus on some frequent everlasting 301 redirection guidelines.
HTTP to HTTPS Redirection.
Many of the domains have legitimate SSL certificates, however in most case, the web site doesn’t redirect to https. The given rule helps you to redirect the web site to https from https. Put given under redirection rule within the .htaccess file to redirect to https from all http requests.
RewriteCond %HTTPS off
RewriteRule ^(.*)$ Error! Hyperlink reference not legitimate. [L,R=301]
Redirect from outdated information to new information on the identical area.
Assume you’ve web site examle.com. If you wish to redirect from instance.com/oldfile.php to instance.com/newfile.php put the given under rule within the .htaccess file.
Redirect 301 /oldfile.php /newfile.php
Redirect outdated area to new area.
Assume you’ve an internet site and two domains instance.org and instance.com for an internet site and at present you’re utilizing instance.com and now you determined you need to use instance.org on your web site. On this case, put given under rule within the .htaccess file.
RewriteCond %HTTP_HOST ^instance.com [NC,OR]
RewriteCond %HTTP_HOST ^www.instance.com [NC]
RewriteRule ^(.*)$ http://instance.org/$1 [L,R=301,NC]
Redirect Non www to www
RewriteCond %HTTP_HOST !^www.
RewriteRule ^(.*)$ Error! Hyperlink reference not legitimate. [R=301,L]
Redirect all file with particular extension to a different extension.
For instance, if you wish to redirect all .htm file to .php
RewriteCond %REQUEST_URI .htm$
RewriteRule ^(.*).htm$ /$1.php [R=301,L]
In the event you want any additional assist please do attain our help division.