install mod rewrite

Introduction:

DigitalOcean is one of the best Cloud Server hosting providers on the internet. I always prefer them to my customers, because it was very easy to manage their servers. I am creating this post because I feel very hard while I do the mod_rewrite in Apache2 Ubuntu in DO (DigitalOcean). This article will help you to enable the rewrite mode in your DO server. 

Enable Rewrite Mod in SSL Enabled Domain:

There are two ports for apache2 server. One was port 80, and the other one was port 443. So when we enable rewrite, We have to check that our domain was SSL enabled domain or not. We can test it simply by the following method. 

SSL Domain Example: https://www.example.com
Non-SSL Enabled Domain: http://www.example.com

If your domain is not SSL enabled domain you have to follow the Non-SSL Based Domain method. Otherwise, the tutorial will not work for you.

If your domain is SSL enabled domain, then start to continue reading.

First of all, you need to open your server with Console. To open, you can use software called Putty, or you can directly access it from the DO dashboard.
  1. Open your DO Dashboard.
  2. Click on the "More" Tab of your Droplet.
  3. Click on the "Access Console" Link.
  4. Now enter the following query in the console window. 
sudo a2enmod rewrite
The above query will enable rewrite mode in your apache2 server. Now follow the below step to enable the rewrite mode in the port 443.
  • Go to the "/etc/apache2/sites-available" using your SFTP Client or by using the command below in your Console.
vi /etc/apache2/sites-available/default-ssl.conf
  • The above query will open a VI Editor in your console.
  • Now you have to add the code that showed below to the "default-ssl.conf" file.
  • To enable editing in VI Editor, You have to enter "I" First.
<IfModule mod_ssl.c>
<VirtualHost _default_:443>
<Directory /var/www/>
	Options Indexes FollowSymLinks MultiViews
	AllowOverride All
	Order allow,deny
	allow from all
</Directory>
  • Now save the file and execute the command given below ( Save file by clicking the "Esc" Button and enter ";wq".
sudo service apache2 restart
  • Finished.

Enable Rewrite Mod in SSL Enabled Domain:

In the above SSL enabled domain, we edited the "default-ssl.conf" but in Non-SSL allowed domain, We don't have to edit that file. Instead of that file, We have to edit the file which likes "example.com.conf" File. This file represents the Port 80.
  • You can edit the file by using "vi  /etc/apache2/sites-available/example.com.conf" command. 
  • Change the "example.com" with your site address.
  • Now copy the code that showed below to that file and saves the file.
<VirtualHost *:80>
<Directory /var/www/>
	Options Indexes FollowSymLinks MultiViews
	AllowOverride All
	Order allow,deny
	allow from all
</Directory>
  • You can save the file by clicking the "Esc" Button and the enter ":wq".
  • Now restart your apache2 server with the "sudo service apache2 restart" command.
  • Finished.
 Now the rewrite function inside the "var/www/" Will work. If you have any doubts in the sudo commands. You can check it out on the internet.

Suggested Article for Webmasters

I hope you well enjoyed this article. If you have any doubts or suggestions related to this article, Please let us know by using the comment box that given below. Thanks

0 comments:

Post a Comment

Wapmaster or Webmaster can Comment Us with the following Comment Box . Don't add Links to your site for Spamming our Blog .. Once you add Comment with Link . It will be deleted immediatly by our Admins .

 
Top