Something Different In Linux

Home » htaccess » What is Mod-Rewrite Module

What is Mod-Rewrite Module

Posted by Rishikesh Vispute Categories: htaccess, Knowledge
What is Mod-Rewrite Module?

Mod_rewrite is merely the Apache module that contains the rewrite engine – other servers will process URL rewriting differently.Mod-Rewrite module uses a rule-based rewriting engine (based on a regular-expression parser) to rewrite requested URLs on the fly. It supports an unlimited number of rules and an unlimited number of attached rule conditions for each rule to provide a really flexible and powerful URL manipulation mechanism.

The RewriteEngine directive enables or disables the runtime rewriting engine. We need to tell Apache where and what to rewrite. You have two options here – more commonly, you can place the code in a .htaccess file. This is nothing more than a text file which when present in a directory will be interpreted by Apache.The other alternative is only available if you have root access and that is to place the code inside your httpd.conf

How can I enable Mod-Rewrite Module?

Before we can rewrite, there is one option we must first set: FollowSymLinks. This is a security feature of the rewrite engine and you will not be able to rewrite without this option. In most cases, this will already be set in the server httpd.conf but you can safely state it again.Additionally, if you use indexes, we must enable the Indexes option.

In order to enable Mod_Rewrite for your site you should create a text file called .htacccess in the directory where you wish the rewrite rules to apply.
================================================== ==========
#The first three lines of this text file should be:
Options +FollowSymLinks
Options +Indexes
RewriteEngine On
#After that you can place your rewrite rules
================================================== ===========

RewriteRule example :=

1] When you want Register a Domain, Find Hosting and Create a Website at to be redirected to Register a Domain, Find Hosting and Create a Website at, add the following in your .htaccess.

RewriteCond %{HTTP_HOST} !^$ [NC]
RewriteRule ^(.*)$$1 [L,R=301]

2] If does not exist, redirect to (Put this in an .htaccess file in your top-level web directory.)

# .htaccess in root of
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$$1 [R]

3] Handle all requests for top-level .html files and files with no extensions (, with a single PHP program /foo/show.php. Also, ignore trailing characters in set { : ; , . } so URLs like “” can be copied-n-pasted from plain text sentences by inattentive users.

# .htaccess in root of
RewriteRule ^/?([^/]*\.html?|[^\./]*)[:;,\.]*$ /foo/show.php [L,NS]

4]Here are some examples for Joomla’s SEF option:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (/|\.htm|\.php|\.html|/[^.]*)$ [NC]
RewriteRule ^(content/|component/) index.php

5]Redirect GET requests for to (and /foo/bar.html to /bar.html). Handle POST requests with PHP program rather than attempting to redirect a POST (which is unlikely to work well).

# .htaccess in foo folder in’s document root
RewriteEngine On
RewriteRule ^/?([^/]*\.html?|[^\./]*)[:;,\.]*$ /$1 [R,L,NS]
RewriteRule ^/?([^/]*\.html?|[^\./]*)[:;,\.]*$ /foo/show.php [L,NS]

Popular Posts

remove index.php fro

How to remove index.php from url in magento Ans : If you ...

PHP-Java bridge on p

  What is php-java bridge? The php-java bridge is the php ...

Set expiration for y

If you want to set the expiration to your site ...

Warning: Parameter 1

Error: Warning: Parameter 1 to modMainMenuHelper::buildXML() expected to be a ...

domain pointing to e

If you domain uses external MX record and it is ...