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 Upload Files in Zenphoto

Knowing how to upload files in Zenphoto is a fundamental skill. In this guide, we share how to go through the process and manage your project and media library quickly and easily.   Step 1: Log in to Zenphoto The first step in the process is to log in to...

How to Back Up your TYPO3 Project

In this article, we outline the step-by-step process for backing up your TYPO3 project, ensuring that all your data, settings, and other essential information are safely stored. Regardless of your level of expertise, this method is simple to follow and provides...

How to Install Themes in TYPO3

Learning how to install themes in TYPO3 is essential, as it enables you to personalize your website fully. Whether you are working on a personal blog or a complex business website, the process of installing a theme in TYPO3 is the same. In this article, we share how...

How to Add Extensions to TYPO3

TYPO3 is a versatile platform that allows you to customize it any way you wish. One of TYPO3's strengths is the so-called extensions that enable you to add any kind of functionality to your website. In this article, we share how to add extensions to TYPO3. What are...

How to Add a Page in TYPO3

TYPO3 is a versatile platform that offers numerous features and an intuitive interface. If you're just getting started with the CMS, one of the first tasks you'll likely complete is creating a new page for your website. In this guide, we showcase how to do so and...



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 Upload Files in Zenphoto

Knowing how to upload files in Zenphoto is a fundamental skill. In this guide, we share how to go through the process and manage your project and media library quickly and easily.   Step 1: Log in to Zenphoto The first step in the process is to log in to...

How to Back Up your TYPO3 Project

In this article, we outline the step-by-step process for backing up your TYPO3 project, ensuring that all your data, settings, and other essential information are safely stored. Regardless of your level of expertise, this method is simple to follow and provides...

How to Install Themes in TYPO3

Learning how to install themes in TYPO3 is essential, as it enables you to personalize your website fully. Whether you are working on a personal blog or a complex business website, the process of installing a theme in TYPO3 is the same. In this article, we share how...

How to Add Extensions to TYPO3

TYPO3 is a versatile platform that allows you to customize it any way you wish. One of TYPO3's strengths is the so-called extensions that enable you to add any kind of functionality to your website. In this article, we share how to add extensions to TYPO3. What are...

How to Add a Page in TYPO3

TYPO3 is a versatile platform that offers numerous features and an intuitive interface. If you're just getting started with the CMS, one of the first tasks you'll likely complete is creating a new page for your website. In this guide, we showcase how to do so and...

How to Use Modules in TYPO3

TYPO3 is a CMS based on a modular architecture, meaning that users can use various built-in tools and add-ons to manage content, other users, configurations, and more. In this guide, we share how to use modules in TYPO3, so you get the most out of them.   What...

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.