May

27


Like the ‘if’ statement in many programming languages, you can use conditional rule to control mod_rewrite redirect. One very common use for RewriteCond is to prevent looping.

The following rule set causes any request starting with home to be redirected to /home.html. The resulting URL, however, starts with home and will therefore trigger the RewriteRule to be run again. The RewriteCond directive ensures that the rule will be skipped if the request is already for home.html and thus avoids this looping.

RewriteCond %{REQUEST_URI} !^/home\.html
RewriteRule ^home /home.html [R]



Similar Posts

Comments

Name (required)

Email (required)

Website

Speak your mind

1 Comment so far

  1. Aletheya on June 1, 2008 9:14 am

    I can’t describe how helpful this article is! it saved my life! thanks for posting it out!

Sponsors




Links