How to use .htaccess rewrite rules?

As you know that today we are living the world where you can find new technology each new day. In the same way here in hosting industry cloud server is the latest of hosting technology which is provided to the customers. And today using a cloud server is one the best web hosting platform where you can really enjoy it with more benefits and more features. And to large scale business are using cloud servers to host their website and the reason behind it is that by using cloud server you get more security, scalability, reliability and also flexibility. And one of the biggest advantages of using Cloud server is that you can access to your data at any place at any time.

So today if you are using a cloud server for your website and if you are looking for information on how to use  .htaccess rewrite rules then here is the complete information. The Apache module mod_rewrite allows you to rewrite the URL requests that come into your server moreover it is based on a regular-expression parser. And when the mod is implemented correctly, only then the mod_rewrite is very powerful. Today there are many different other applications for mod_rewrite you can know about.

Cloud Server Plans

9571 Save 44%
5360 / month
7.4 / hour
  • Disk Space : 80 GB SSD
  • 4 Core
  • RAM : 8 GB
  • Bandwidth : 5 TB
6929 Save 44%
3880 / month
5.3 / hour
  • Disk Space : 80 GB SSD
  • 2 Core
  • RAM : 6 GB
  • Bandwidth : 5 TB
4786 Save 44%
2680 / month
3.7 / hour
  • Disk Space : 60 GB SSD
  • 2 Core
  • RAM : 4 GB
  • Bandwidth : 4 TB
19214 Save 44%
10760 / month
14.9 / hour
  • Disk Space : 120 GB SSD
  • 8 Core
  • RAM : 16 GB
  • Bandwidth : 6 TB
38286 Save 44%
21440 / month
29.7 / hour
  • Disk Space : 320 GB SSD
  • 12 Core
  • RAM : 32 GB
  • Bandwidth : 7 TB
2545 Save 44%
1425 / month
1.9 / hour
  • Disk Space : 50 GB SSD
  • 2 Core
  • RAM : 2 GB
  • Bandwidth : 3 TB

Before moving into the rewrite .htaccess rules go through this-

You have to create a plain text .htaccess file. Once after creating a plain text .htaccess file replace the folder name, file.html and save the changes. Now to upload the file to your root document use this command-


So you've uploaded the file, the rewrite rule should take effect immediately.

Now to direct requests for one subdirectory to a different subdirectory or the document root

Filename: .htaccess

Options +FollowSymLinks

RewriteEngine On

RewriteRule ^folder1.*$ [R=301,L]

This .htaccess file will redirect the path which you have given, and also choose the version which you redirects to your homepage or to any other page.

Filename: .htaccess.

Options +FollowSymLinks

RewriteEngine On

RewriteRule ^folder1.*$ [R=301,L]

Now if you want to upload any folder then use this command

Filename: index.html



Mod_rewrite is working!



Now you will see the URL change to

or You should be redirected to and see the test page content.

Direct request to a subdirectory becomes

This .htaccess file will redirect to

Filename: .htaccess

Options +FollowSymLinks

RewriteEngine On

RewriteCond %{HTTP_HOST}$ [NC]

RewriteCond %{HTTP_HOST} !folder1

RewriteRule ^(.*)$$1 [R=301,L]

To add www or https becomes Or, becomes

To add www use this command-


Options +FollowSymLinks

RewriteEngine on

RewriteCond %{HTTP_HOST} ^ [NC]

RewriteRule ^(.*)$$1 [R=301,L]

To add https use this command-

Filename: .htaccess

RewriteEngine On

RewriteCond %{SERVER_PORT} 80

RewriteRule ^(.*)$$1 [R,L]

How to redirect the website using a .htaccess file?

Here you will be explained on how to create a .htaceess file for redirecting the website or the website content. This will not be redirecting any of the emails for the domain.

As a configuration file .htacess is very powerful. Here even the slightest syntax error like that of missing the space can result in the displaying the content not correctly at all.

As the .htaccess is a hidden system file, one should make sure that the FTP client is being configured to show the hidden files. It is usually an option in the programs preference options.

First and foremost thing that needs to be performed is to empty the text file using the text editor such as the notepad and then save it as an htaccess.txt.

Now you need to edit the content of the file. Below is an example:

301 (Permanent) Redirect: You need to point the entire website to a different URL permanently. This is one of the most common types of redirects and it is very useful in most of the situations. Here we will be redirecting the “” domain:

This will allow it to redirect the entire website to another domain name
Redirect 301 /

302 (Temporary) Redirect: Here you will point the entire website to a different temporary URL. This can be very useful for the SEO purposes when a temporary landing page and for switching back to the main landing page at a later date:

# This will allow you to redirect the entire website to any other recently purchase domain or sub-domain

Redirect 302 /’


Redirecting the index.html to a specific subfolder:

# Here it will be allowed to you to redirect the index.html to a specific subfolder

Redirect /index.html


Redirecting the old file to a new file path:

# Redirecting the old file path to the new file path

Redirect /olddirectory/oldfile.html


Redirecting to the specific index page:

# Provide Specific Index Page (Set the default handler)

DirectoryIndex index.html

Now you need to upload this file and then rename it to .htaccess.

If you are looking to make complex changes to the way the URL is displayed, they should be knowing the .htaccess rewrite rules. You will be able to do things like adding “www” at the beginning of the URL, redirecting all the requests to the subfolder and keeping the rest of the URL, etc.