Apache mod_rewrite examples

General

The mod_rewrite is a very powerful module for manipulating the server side path ways and conversions with Apache. To further my studies on this feature, I have dedicated this page to everything about it.

Example 1: Rewriting with some matches

My first example is composed of a very basic transformation from one value to another.


RewriteEngine On
RewriteBase /thebase
RewriteRule ^matchone/(.*) /MatchOne/$1 [R=301,L]
RewriteRule ^matchtwo/(.*) /MatchTwo/$1 [R=301,L]
RewriteRule ^Match/(.*) /match/$1 [R=301,L]
# send anyone going target_a, redirect to to target_b
RewriteRule ^target_a/(.*)/?$ http://site.domain.com/default/index.php/$1 [L]

Example 2: Rewriting with some matches except for visits from a specific IP Address

 

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>