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.

Start a website with a 99.9% uptime!

Prices starting at 33.48€40.18€$35.88$43.06/year!

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 sub-directory of your domain name (domain.com/site/ for example), it will be necessary to make a couple 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

 

    1. Restart the Apache web server:
  /etc/init.d/apache2 restart

 

    1. 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.

It's Time to Share Your Story.

Get Free Web Hosting. Start a website, and introduce yourself to the world.

Get Free Hosting
Related Posts

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 […]

“Parse error: syntax error, unexpected T_STRING” error appears on my website

In this tutorial, we’re going to provide details regarding the error message syntax error, unexpected T_STRING, including the meaning and ways to fix it. What Does the Error Mean? The error message Parse error: syntax error, unexpected T_STRING usually appears […]

ASP.NET Manager

How Can I Access the ASP.NET Manager? You can access the AwardSpace.com ASP.NET Manager in two easy steps: Sign in to your AwardSpace web hosting account. Under the Advanced Tools area, click on the ASP.NET Manager link. What Type of […]

awardspace logo
Where Ideas Turn Into Websites