httpd-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Luca Toscano <>
Subject Re: [users@httpd] RewriteRule: Pattern matching and grouping part of the URL expands to its local filesystem path
Date Tue, 29 Aug 2017 13:00:26 GMT
Hi Gustau,

2017-08-22 9:01 GMT+02:00 Gustau Perez <>:

>    Hello everybody,
>    I’ve checking all kinds of sources of information so far without
> success, I hope I didn’t miss anything.
>    I have a very simple RewriteRule which should take the requested
> resource part. What I want to achieve is to prepend an string before that
> matched path. Something like:
> RewriteRule   ^(.*)$             http://myserver/special_path/$1 [R=301]
>    I’d say that should take the requested resource path and redirect the
> client to a new location. It does work in some places, but I’d like to use
> under a conditional <If>. When I do
> that, the match is instead expanded to the local filesystem path, if I
> request the “/“ (root) of the server, the client is being redirected to:
>       http://myserver/special_path/var/www/html
>    Never mind about the DocumentRoot path. Anyway, that’s not the desired
> behaviour.
>    Perhaps we’re doing something wrong, but what puzzles me is the fact
> that if move the redirect logic outside the <If> block, then it apparently
> works fine.

I'd suggest to try Redirect or RedirectMatch for these use cases, they are
less complicated and more straightforward:

As you can see in
the <If> block accepts only directives that are usable in the directory
context (, and
this is a special note in the RewriteRule docs that might clarify what's

"In per-directory context (Directory and .htaccess), the Pattern is matched
against only a partial path, for example a request of "/app1/index.html"
may result in comparison against "app1/index.html" or "index.html"
depending on where the RewriteRule is defined."

If I am right a note in the docs might clarify any doubts like yours, but
need to double check first :)


View raw message