It isn’t a rocket science to create a .htaccess file to redirect your site or site content. The given below instructions will help you in understanding it in an easier way. It will not redirect any emails for your domains.
As a configuration file, there is no denying that .htaccess is very powerful. Even a minute or slight error in syntax (like a missing space) can result in your content not displaying correctly or at all.
Being a hidden system file, make sure your FTP client is configured to show hidden files. You can find it in the program’s preferences/options.
1. You can begin by creating an empty text file by using a text editor such as notepad, and save it as htaccess.txt.
The main motive to 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 you have uploaded it to the server, you can rename the file to .htaccess.
2. Editing the content of the file. Check the following examples:
301 (Permanent) Redirect: You have to point an entire site to a different URL on a permanent basis. This is considered the most common type of redirect and is useful in most of the situations. In this example, we are redirecting to the “st-example.com” domain:
# This way you get to redirect your entire website to any other domain
Redirect 301 / http://st-example.com/
302 (Temporary) Redirect: You have to point an entire site to a completely different temporary URL. This is quite useful for SEO purposes when you have a temporary landing page and then plan to switch back to your main landing page at a later date.
# Through this you get to redirect your entire website to any other domain
Redirect 302 / http://st-example.com/
To redirect index.html to a specific subfolder:
# By doing this you redirect index.html to a specific subfolder
Redirect /index.html http://example.com/newdirectory/
To redirect an old file to a new file path:
# This way you redirect old file path to a new file path
Redirect /olddirectory/oldfile.html http://example.com/newdirectory/newfile.html
To redirect to a specific index page:
# With this, you get to provide Specific Index Page (Set the default handler)
3. Now, upload the file and re-name it to .htaccess.
- If using a text editor, make sure that you save the file as plain text.
Now, you must have understood that creating a .htaccess file to redirect your site or site content isn’t that difficult. Just follow the right procedure and be a little careful. That’s it.
I hope you had fun reading this article as much as I had while writing it. For any doubts or queries, feel free to ask in the comments section below. Do not forget to subscribe to our newsletter and share it on Facebook, Twitter, Google+ and LinkedIn.