How to use mod_rewrite (RewriteRule/RewriteCond)

Home » Knowledge Base » Website Management – Advanced » .htaccess » How to use mod_rewrite (RewriteRule/RewriteCond)

In this tutorial, we are going to walk you through the process of enabling mod_rewrite on your AwardSpace web server.

 

What is Mod_Rewrite?

Mod_rewrite is an Apache module that helps you perform redirects and define rewrite rules with the use of a .htaccess file.

For more detailed information, please visit the official Apache Module mod_rewrite page.

 

How Can I Enable the Apache Rewrite Module on a Shared Hosting Account?

The Apache module mod_rewrite comes preinstalled with all shared hosting plans. Therefore, you will not be required to perform any manual installation of the module on the server.

In order to enable the rewrite module on your website, make sure that your .htaccess contains the following two lines of code:

  RewriteEngine On
  RewriteBase /

 

At the end, your code should look similar to the following:

  RewriteEngine On
  RewriteBase /
  RewriteRule ^index\.php$ - [L]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule . /index.php [L]

 

Note: If you have installed your application in a subdirectory of your domain name (domain.com/site/ for example), it will be necessary to make a couple of slight modifications to the code:

  RewriteEngine On
  RewriteBase /site/
  RewriteRule ^index\.php$ - [L]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule . /site/index.php [L]

 

Please make sure that you replace site with your actual directory name.

 

How Can I Enable the Rewrite Module on a VPS Server?

On a Debian/Ubuntu server, the Apache rewrite module is installed, but not enabled by default.

If you have an active VPS account and wish to enable mod_rewrite on your web server, you should perform the following steps:

 

1. Log into your VPS account via SSH and execute the following command in Terminal:

  a2enmod rewrite

 

2. Restart the Apache web server:

  /etc/init.d/apache2 restart

 

3. Locate the main .htaccess file in your web application’s root directory, and then copy and paste the below code into it:

  RewriteEngine On
  RewriteBase /
  RewriteRule ^index\.php$ - [L]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule . /index.php [L]

 

Save the changes you have just made and re-test your application.

Was this post helpful?

i

Relevant tags:

Connect

Latest posts:

How to Find Modules in MediaWiki

After you install MediaWiki, log in to the CMS, and presumably install extensions, it is time to learn how to find modules in MediaWiki.   What are MediaWiki Modules Modules in MediaWiki are Lua-based scripts that allow you to add various functionalities to your...

How to Fix MediaWiki Internal Error: A Step-By-Step Guide

MediaWiki Internal Error message can be very frustrating and can significantly harm your MediaWiki project. Luckily, the issue can be fixed in a few easy-to-follow steps to get your website up and running in no time. There are various causes for the issue: Incorrect...

How to Add Infobox Module in MediaWiki

The Infobox in MediaWiki is a handy tool for presenting content and key information in a structured and visually pleasing way. Infoboxes are useful for any kind of MediaWiki project and can provide your readers with a quick snapshot of important data and details. In...

How to Install a MediaWiki Skin

In MediaWiki, skins determine the visual appearance of your wiki website. Skins define how content is presented to users and include such settings for the overall website layout, typography, color scheme, and more. By default, when you install MediaWiki, the platform...

How to Create a Page in MediaWiki

Creating pages in MediaWiki is а core feature that allows you to add content to your MediaWiki website. Whether you are adding details for a project, contributing to a knowledge base, or anything else, learning how to create a page in MediaWiki is crucial for your...



Create a website for free!


Free forever

Our Support Team is Here to Help

 

If you need any questions answered, don't hesitate and contact us. Click the button below and follow the instructions. You can expect an answer within an hour.

 

Contact AwardSpace

 

iNewest knowledge base articles

How to Find Modules in MediaWiki

After you install MediaWiki, log in to the CMS, and presumably install extensions, it is time to learn how to find modules in MediaWiki.   What are MediaWiki Modules Modules in MediaWiki are Lua-based scripts that allow you to add various functionalities to your...

How to Fix MediaWiki Internal Error: A Step-By-Step Guide

MediaWiki Internal Error message can be very frustrating and can significantly harm your MediaWiki project. Luckily, the issue can be fixed in a few easy-to-follow steps to get your website up and running in no time. There are various causes for the issue: Incorrect...

How to Add Infobox Module in MediaWiki

The Infobox in MediaWiki is a handy tool for presenting content and key information in a structured and visually pleasing way. Infoboxes are useful for any kind of MediaWiki project and can provide your readers with a quick snapshot of important data and details. In...

How to Install a MediaWiki Skin

In MediaWiki, skins determine the visual appearance of your wiki website. Skins define how content is presented to users and include such settings for the overall website layout, typography, color scheme, and more. By default, when you install MediaWiki, the platform...

How to Create a Page in MediaWiki

Creating pages in MediaWiki is а core feature that allows you to add content to your MediaWiki website. Whether you are adding details for a project, contributing to a knowledge base, or anything else, learning how to create a page in MediaWiki is crucial for your...

How to Install MediaWiki Extensions

Now that you have installed MediaWiki and learned how to log in to the CMS, it is time to extend MediaWiki's functionality via extensions. MediaWiki extensions are sets of files that add various types of functionality to your MediaWiki website. You can use extensions...

Even more web tutorials

Check out our web hosting knowledge base and the WordPress tutorials to learn more, and be better prepared for your website creation and maintenance journey.