RewriteRule with absolute URL substitution not performing as expected

The Apache RewriteRule documentation says that to perform an external redirect back to the current host, you have to use the [R] flag rather than just using an absolute URL in the substitution. I don’t find that to be the case though, with Apache 2.2.4 on CentOS 4.

Absolute URL
If an absolute URL is specified, mod_rewrite checks to see whether the hostname matches the current host. If it does, the scheme and hostname are stripped out and the resulting path is treated as a URL-path. Otherwise, an external redirect is performed for the given URL. To force an external redirect back to the current host, see the [R] flag below.

I have the following in httpd.conf:

RewriteRule A.html [L]

Requesting results in an external redirect and the rewrite log shows the following:

(2) init rewrite engine with requested uri /A.html
(3) applying pattern 'A.html' to uri '/A.html'
(2) rewrite '/A.html' -> ''
(2) implicitly forcing redirect (rc=302) with
(1) escaping for redirect
(1) redirect to [REDIRECT/302]

The stripping described in the documentation is not happening. Note the “implicitly forcing redirect”.

Am I misunderstanding something or making a mistake, is there a bug in this version of Apache, is the documentation just plain wrong? What’s the deal?

dklynn, I’m sorry, but I can’t make heads or tails of your replies in this thread. I’m not sure you understand the point I’m making in my post.

  1. This is the syntax of a RewriteRule:
RewriteRule Pattern Substitution [flags]
  1. Apache documentation says that if the Substitution is an absolute URL pointing to the current host, it will not perform an external redirect. It says you have to use the [R] flag to perform an external redirect in that situation.

  2. In fact, making Substitution an absolute URL pointing to the current host is resulting in an external redirect when I test it. The rewrite log indicates this as “implicitly forcing redirect”. The [R] flag is not used.

I’m asking what the explanation is for the discrepancy between the documented behavior and the actual behavior.

That was also my understanding, but that’s not what’s happening :slight_smile:

Same thing happening here.
Apache 2.2.1 on Windows 7

Weird! It does it indeed look as though the manual is incorrect!


Sorry that I’ve been incomprehensible.

Your syntax is correct, I can’t argue with the Apache documentation and am at a loss as to why it’s acting the way I think it should act when the official docs say it should work otherwise.



My understanding is that you can use the R=301 to force the redirection to be displayed OR use an absolute (EXTERNAL) redirect to do the same thing (external redirects, i.e., those with http://{yadda-yadda} MUST be displayed so pirates can’t merely use your web pages “on their websites”). Absolute (INTERNAL) redirects tend to confuse Apache as it starts looking for physical path information but is useful when the directory level gets confusing - that will NOT be displayed without the R flag.



302 is a temporary redirect (so SE’s won’t update). Use the R=301 to send the permanent redirection code.