How to configure redirection using .htaccess file. Htaccess is file which is used to make changes to your web server configuration without editing the server configuration file. This .htaccess file will be placed in your website root directory.
In this guide you are going to learn to how to configure some list of redirections which is mostly needed for your SEO and ranking in search engines.
- Create an empty text file using a text editor such as notepad, and save it as htaccess.txt
- The reason you should save the file as htaccess.txt is because many operating systems and FTP applications are unable to read or view
.htaccess
files by default. Once uploaded to the server you can rename the file to.htaccess
.
- The reason you should save the file as htaccess.txt is because many operating systems and FTP applications are unable to read or view
- Edit the contents of the htaccess.txt file. Below are some example redirects you can use. They are labeled in accordance to what actions they will perform.
-
302 (Temporary) Redirect:
Point an entire site to a different temporary URL. This is useful for SEO purposes when you have a temporary landing page and plan to switch back to your main landing page at a later date:
# This allows you to redirect your entire website to any other domain Redirect 302 / http://example.com/
-
301 (Permanent) Redirect:
Use a 301 redirect .htaccess to point an entire site to a different URL on a permanent basis. This is the most common type of redirect and is useful in most situations. In this example, we are redirecting to the "example.com" domain.
When adding the following to your website's .htaccess file, be sure to replace example.com with your own domain name.
# This allows you to redirect your entire website to any other domain Redirect 301 / http://example.com/
-