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 Log in to TYPO3

TYPO3 is a powerful CMS platform that allows you to build a fully functional and aesthetically pleasing website. The platform is known for its versatility and long list of features. In another article, we shared how you can install TYPO3 on any of the AwardSpace...

How to Install TYPO3

You can install TYPO3 on all the AwardSpace hosting services—free web hosting, shared hosting, and premium plans such as Semi-Dedicated Hosting and VPS hosting. All AwardSpace hosting services are tailored to run TYPO3 smoothly, regardless of your website’s size or...

How to Add Products to Zen Cart: A Step-By-Step Guide

After you install Zen Cart and log in to the admin panel, you can start adding products to your online store. This guide walks you through the process step by step.   How to Add Products to Zen Cart To add a product to Zen Cart, you need to follow a few simple...

How to Log in to Zen Cart

Once you install Zen Cart, you can log in to the CMS and start working on your project. The login process is simple and is comprised of only a few steps.   How to Log in to Zen Cart There are two ways to log in to Zen Cart: Method 1: Login by following the...

How to Install Zen Cart

You can install Zen Cart with any of the AwardSpace hosting plans—free web hosting, shared hosting, and advanced plans such as Semi-Dedicated Hosting and VPS hosting. Each AwardSpace hosting service is tailored to run Zen Cart flawlessly and smoothly, regardless of...



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 Log in to TYPO3

TYPO3 is a powerful CMS platform that allows you to build a fully functional and aesthetically pleasing website. The platform is known for its versatility and long list of features. In another article, we shared how you can install TYPO3 on any of the AwardSpace...

How to Install TYPO3

You can install TYPO3 on all the AwardSpace hosting services—free web hosting, shared hosting, and premium plans such as Semi-Dedicated Hosting and VPS hosting. All AwardSpace hosting services are tailored to run TYPO3 smoothly, regardless of your website’s size or...

How to Add Products to Zen Cart: A Step-By-Step Guide

After you install Zen Cart and log in to the admin panel, you can start adding products to your online store. This guide walks you through the process step by step.   How to Add Products to Zen Cart To add a product to Zen Cart, you need to follow a few simple...

How to Log in to Zen Cart

Once you install Zen Cart, you can log in to the CMS and start working on your project. The login process is simple and is comprised of only a few steps.   How to Log in to Zen Cart There are two ways to log in to Zen Cart: Method 1: Login by following the...

How to Install Zen Cart

You can install Zen Cart with any of the AwardSpace hosting plans—free web hosting, shared hosting, and advanced plans such as Semi-Dedicated Hosting and VPS hosting. Each AwardSpace hosting service is tailored to run Zen Cart flawlessly and smoothly, regardless of...

How to Log in to phpBB

Now that you have installed phpBB, it is time to learn how to log in to the system and start working with it. The process is simple and is comprised of only a few steps.   How to Log in to phpBB There are several ways you can use to log in phpBB. The process...

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.