mod_rewrite

References

https://httpd.apache.org/docs/current/rewrite/flags.html

http://httpd.apache.org/docs/current/mod/mod_rewrite.html

RewriteEngine                <On|Off>

RewriteBase

/.

/|.

Else all paths must be preceded by ‘/’.

RewriteRule <regex> <target> [[Flags[,...]]]

Example

RewriteRule

^/zz$ /X.html [PT].

Without RewriteBase.

Test

RewriteRule ^Test$ Testing [R].

Simple Internal Redirect.

Default.

That is, no flag.

External Redirect.

RewriteRule

^/foo\.html$ bar.html [R].

Flags

_[_ <flag[,]>

No space to separate.

Comma separated.

N and NC are entirely different.

NC

No case.

Case insensitive.

N

Begin re-evaluation from the beginning with present.

! can result in a loop.

R.

L

Last.

Terminate further evaluation.

Rewrite rules are recursed.

RewriteLogLevel

[>= 6].

RewriteLog

SYSOUT.

RewriteDocument        <ErrorNo>        “Message”|URL

Rewrite condition.

RewriteCond <expression> -<test> <combination>
RewriteCond <RewriteRule>
<expression>
<expression> Variables : %{<variable>}

REQUEST_FILENAME

Full path of the request.

C:/_/..        Windows

REQUEST_URI

Path after first slash.

<test>

‘!’ for inversion.

-<operator>

operator

f

File.

d

Directory.

<combination>

‘[OR]’.

Cascading conditions for a single rule.

Tip. To debug you may print the expanded condition expression by using it in a rewriterule target.

?requestURI got repeated a few times?

________________.

Redirect 404 /

Redirects 404 errors to page.

Updated: 2026 Aug 19