Re: RewriteRule: Pattern matching and grouping part of the URL expands to its local filesystem path

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Gustau,

2017-08-22 9:01 GMT+02:00 Gustau Perez <gustau.perez@xxxxxxxxxxx>:

   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:


   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:

https://httpd.apache.org/docs/2.4/mod/mod_alias.html#redirect

As you can see in https://httpd.apache.org/docs/current/mod/core.html#if the <If> block accepts only directives that are usable in the directory context (https://httpd.apache.org/docs/current/mod/directive-dict.html#Context), and this is a special note in the RewriteRule docs that might clarify what's happening:

"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 :)

Luca

[Index of Archives]     [Open SSH Users]     [Linux ACPI]     [Linux Kernel]     [Linux Laptop]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Squid]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]

  Powered by Linux