You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by "Lentes, Bernd" <be...@helmholtz-muenchen.de> on 2020/12/09 16:35:04 UTC
[users@httpd] some questions to mod_rewrite
Hi,
i just setup a Nextcloud instance in conjunction with OnlyOffice.
NC makes heavy use of mod_rewrite and i try to understand it.
mod_rewrite isn't easy, so i have some questions and hope for help:
1. Is a RewriteCond just valid for the consequent rule or for all consequent rules ?
2. Example: "RewriteRule ^core/js/oc.js$ index.php [PT,E=PATH_INFO:$1]"
Are Backreferences also in flags possible ?
What is the content of $1 ? I thought backreferences belong to parts of the pattern which are in parentheses ?
There are no parentheses.
3. Example: RewriteCond %{REQUEST_FILENAME} !\.(css|js|svg|gif|png|html|ttf|woff2?|ico|jpg|jpeg|map|webm|mp4|mp3|ogg|wav)$
The ! (exclamation mark) stands for a negotiation. Does that mean this condition is only fullfilled if the file does NOT have an extension
like .css, .js ... ?
4. Example: RewriteRule .* - [env=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
What does this rule do ?
All requests (.*) aren't substituted (-). But ... an environment variable HTTP_AUTHORIZATION is set to ... ?
What means %{HTTP:Authorization} ? Is that also a kind of a backreference ?
More questions will follow :-))
Thanks.
Bernd
--
Bernd Lentes
Head of Systemadministration
Institute for Metabolism and Cell Death (MCD)
Building 25 - office 122
HelmholtzZentrum München
bernd.lentes@helmholtz-muenchen.de
phone: +49 89 3187 1241
phone: +49 89 3187 3827
fax: +49 89 3187 2294
http://www.helmholtz-muenchen.de/mcd
Helmholtz Zentrum München
Helmholtz Zentrum Muenchen
Deutsches Forschungszentrum fuer Gesundheit und Umwelt (GmbH)
Ingolstaedter Landstr. 1
85764 Neuherberg
www.helmholtz-muenchen.de
Aufsichtsratsvorsitzende: MinDir.in Prof. Dr. Veronika von Messling
Geschaeftsfuehrung: Prof. Dr. med. Dr. h.c. Matthias Tschoep, Kerstin Guenther
Registergericht: Amtsgericht Muenchen HRB 6466
USt-IdNr: DE 129521671
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org
Re: [users@httpd] some questions to mod_rewrite
Posted by Daniel Ferradal <df...@apache.org>.
To find out if they are reasonable I would ask the nextcloud guys.
They may be placeholder directives in case you are using certain
plugin of theirs or similar.
Cheers
El jue, 17 dic 2020 a las 19:36, Lentes, Bernd
(<be...@helmholtz-muenchen.de>) escribió:
>
>
>
> ----- On Dec 17, 2020, at 5:19 PM, Daniel Ferradal dferradal@apache.org wrote:
>
> > Hey Bernd,
> >
> > I remember my first head scratches with regex, they can be so
> > confusing and difficult to understand.
> >
> > Although I remember preciously the day https://regexone.com/ opened my
> > eyes. It just took me 45 minutes to understand the basics of it.
> >
> > I dearly recommend you to do the same and visit the site, once you
> > grasp it, regex will be tones of times easier to deal with.
> >
> > Cheers
> >
>
> Hi Daniel,
>
> my problems are more the understanding of RewriteRule in vhost- or per-directory context.
> I try to understand how rewriting works in a up-to-date Nextcloud.
>
> This is the scenario:
>
> root@nc-mcd:~# ll /var/www/nextcloud
> total 116
> drwxr-x--- 1 www-data www-data 396 Dec 9 20:33 ./
> drwxr-xr-x 1 root root 90 Dec 14 19:01 ../
> drwxr-x--- 1 www-data www-data 778 Dec 9 20:33 3rdparty/
> drwxr-x--- 1 www-data www-data 1154 Dec 14 22:20 apps/
> -rw-r----- 1 www-data www-data 17234 Dec 9 20:30 AUTHORS
> drwxr-x--- 1 www-data www-data 72 Dec 14 19:08 config/
> -rw-r----- 1 www-data www-data 3893 Dec 9 20:30 console.php
> -rw-r----- 1 www-data www-data 34520 Dec 9 20:30 COPYING
> drwxr-x--- 1 www-data www-data 458 Dec 9 20:33 core/
> -rw-r----- 1 www-data www-data 5083 Dec 9 20:30 cron.php
> -rw-r----- 1 www-data www-data 4450 Dec 14 19:08 .htaccess <======
> -rw-r----- 1 www-data www-data 156 Dec 9 20:30 index.html
> -rw-r----- 1 www-data www-data 2960 Dec 9 20:30 index.php
> drwxr-x--- 1 www-data www-data 126 Dec 9 20:30 lib/
> -rw-r----- 1 www-data www-data 283 Dec 9 20:30 occ
> drwxr-x--- 1 www-data www-data 18 Dec 9 20:30 ocm-provider/
> drwxr-x--- 1 www-data www-data 50 Dec 9 20:30 ocs/
> drwxr-x--- 1 www-data www-data 18 Dec 9 20:30 ocs-provider/
> -rw-r----- 1 www-data www-data 3102 Dec 9 20:30 public.php
> -rw-r----- 1 www-data www-data 5332 Dec 9 20:30 remote.php
> drwxr-x--- 1 www-data www-data 158 Dec 9 20:30 resources/
> -rw-r----- 1 www-data www-data 26 Dec 9 20:30 robots.txt
> -rw-r----- 1 www-data www-data 2379 Dec 9 20:30 status.php
> drwxr-x--- 1 www-data www-data 26 Dec 9 20:30 themes/
> drwxr-x--- 1 www-data www-data 42 Dec 9 20:31 updater/
> -rw-r----- 1 www-data www-data 101 Dec 9 20:30 .user.ini
> -rw-r----- 1 www-data www-data 362 Dec 9 20:33 version.php
>
> There is a .htaccess in the folder.
> So per-directory context. Now from the official apache documentation:
>
> What is matched ?
> ...
> "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.
> The directory path where the rule is defined is stripped from the currently mapped filesystem path before comparison (up to and including a trailing slash)."
>
> So in this case this would mean, as the .htaccess file is in /var/www/nextcloud/, this path (/var/www/nextcloud/) is stripped before comparing.
>
> "The net result of this per-directory prefix stripping is that rules in this context only match against =====> the portion of the currently mapped FILESYSTEM PATH "below" <======= where the rule is defined.
> I understand it that way that a request of /somepath/somefile, which mapps maybe via an alias to /var/www/nextcloud/ looks now IN THE FILESYSTEM for somepath/somefile below /var/www/nextcloud/
> That's my understanding and afters hours of fighting with rewrite i was happy and proud to get it. But ...
>
> Here are the some rewriterules from that .htaccess:
>
> RewriteRule ^\.well-known/host-meta /public.php?service=host-meta [QSA,L]
> RewriteRule ^\.well-known/host-meta\.json /public.php?service=host-meta-json [QSA,L]
> RewriteRule ^\.well-known/webfinger /public.php?service=webfinger [QSA,L]
> RewriteRule ^\.well-known/nodeinfo /public.php?service=nodeinfo [QSA,L]
> RewriteRule ^\.well-known/carddav /remote.php/dav/ [R=301,L]
> RewriteRule ^\.well-known/caldav /remote.php/dav/ [R=301,L]
> RewriteRule ^remote/(.*) remote.php [QSA,L]
> RewriteRule ^(?:build|tests|config|lib|3rdparty|templates)/.* - [R=404,L]
> RewriteCond %{REQUEST_URI} !^/\.well-known/(acme-challenge|pki-validation)/.*
> RewriteRule ^(?:\.|autotest|occ|issue|indie|db_|console).* - [R=404,L]
>
> Let's take the first rule:
> RewriteRule ^\.well-known/host-meta /public.php?service=host-meta [QSA,L]
> Following my assumption (the rule is defined in a .htaccess in /var/www/nextcloud, so /var/www/nextcloud/ is stripped), the pattern '^\.well-known/host-meta' is matched again the filesystem "below" the .htaccess.
> But there is no folder ".well-known.
> And the other rules: there are no folders remote/, no folder or file named build, tests, config, lib, ...
> Then all these rules wouldn't make sense !?!
>
> I thought i got it, but now i'm completely stunned.
> Can someone bring light into it ? Is my understanding wrong, that in per-directory context the pattern is matched against the fs ? Although the doc says it ?
>
> Thanks.
>
>
> Bernd
> Helmholtz Zentrum München
>
> Helmholtz Zentrum Muenchen
> Deutsches Forschungszentrum fuer Gesundheit und Umwelt (GmbH)
> Ingolstaedter Landstr. 1
> 85764 Neuherberg
> www.helmholtz-muenchen.de
> Aufsichtsratsvorsitzende: MinDir.in Prof. Dr. Veronika von Messling
> Geschaeftsfuehrung: Prof. Dr. med. Dr. h.c. Matthias Tschoep, Kerstin Guenther
> Registergericht: Amtsgericht Muenchen HRB 6466
> USt-IdNr: DE 129521671
>
--
Daniel Ferradal
HTTPD Project
#httpd help at Freenode
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org
Re: [users@httpd] some questions to mod_rewrite
Posted by "Lentes, Bernd" <be...@helmholtz-muenchen.de>.
----- On Dec 17, 2020, at 5:19 PM, Daniel Ferradal dferradal@apache.org wrote:
> Hey Bernd,
>
> I remember my first head scratches with regex, they can be so
> confusing and difficult to understand.
>
> Although I remember preciously the day https://regexone.com/ opened my
> eyes. It just took me 45 minutes to understand the basics of it.
>
> I dearly recommend you to do the same and visit the site, once you
> grasp it, regex will be tones of times easier to deal with.
>
> Cheers
>
Hi Daniel,
my problems are more the understanding of RewriteRule in vhost- or per-directory context.
I try to understand how rewriting works in a up-to-date Nextcloud.
This is the scenario:
root@nc-mcd:~# ll /var/www/nextcloud
total 116
drwxr-x--- 1 www-data www-data 396 Dec 9 20:33 ./
drwxr-xr-x 1 root root 90 Dec 14 19:01 ../
drwxr-x--- 1 www-data www-data 778 Dec 9 20:33 3rdparty/
drwxr-x--- 1 www-data www-data 1154 Dec 14 22:20 apps/
-rw-r----- 1 www-data www-data 17234 Dec 9 20:30 AUTHORS
drwxr-x--- 1 www-data www-data 72 Dec 14 19:08 config/
-rw-r----- 1 www-data www-data 3893 Dec 9 20:30 console.php
-rw-r----- 1 www-data www-data 34520 Dec 9 20:30 COPYING
drwxr-x--- 1 www-data www-data 458 Dec 9 20:33 core/
-rw-r----- 1 www-data www-data 5083 Dec 9 20:30 cron.php
-rw-r----- 1 www-data www-data 4450 Dec 14 19:08 .htaccess <======
-rw-r----- 1 www-data www-data 156 Dec 9 20:30 index.html
-rw-r----- 1 www-data www-data 2960 Dec 9 20:30 index.php
drwxr-x--- 1 www-data www-data 126 Dec 9 20:30 lib/
-rw-r----- 1 www-data www-data 283 Dec 9 20:30 occ
drwxr-x--- 1 www-data www-data 18 Dec 9 20:30 ocm-provider/
drwxr-x--- 1 www-data www-data 50 Dec 9 20:30 ocs/
drwxr-x--- 1 www-data www-data 18 Dec 9 20:30 ocs-provider/
-rw-r----- 1 www-data www-data 3102 Dec 9 20:30 public.php
-rw-r----- 1 www-data www-data 5332 Dec 9 20:30 remote.php
drwxr-x--- 1 www-data www-data 158 Dec 9 20:30 resources/
-rw-r----- 1 www-data www-data 26 Dec 9 20:30 robots.txt
-rw-r----- 1 www-data www-data 2379 Dec 9 20:30 status.php
drwxr-x--- 1 www-data www-data 26 Dec 9 20:30 themes/
drwxr-x--- 1 www-data www-data 42 Dec 9 20:31 updater/
-rw-r----- 1 www-data www-data 101 Dec 9 20:30 .user.ini
-rw-r----- 1 www-data www-data 362 Dec 9 20:33 version.php
There is a .htaccess in the folder.
So per-directory context. Now from the official apache documentation:
What is matched ?
...
"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.
The directory path where the rule is defined is stripped from the currently mapped filesystem path before comparison (up to and including a trailing slash)."
So in this case this would mean, as the .htaccess file is in /var/www/nextcloud/, this path (/var/www/nextcloud/) is stripped before comparing.
"The net result of this per-directory prefix stripping is that rules in this context only match against =====> the portion of the currently mapped FILESYSTEM PATH "below" <======= where the rule is defined.
I understand it that way that a request of /somepath/somefile, which mapps maybe via an alias to /var/www/nextcloud/ looks now IN THE FILESYSTEM for somepath/somefile below /var/www/nextcloud/
That's my understanding and afters hours of fighting with rewrite i was happy and proud to get it. But ...
Here are the some rewriterules from that .htaccess:
RewriteRule ^\.well-known/host-meta /public.php?service=host-meta [QSA,L]
RewriteRule ^\.well-known/host-meta\.json /public.php?service=host-meta-json [QSA,L]
RewriteRule ^\.well-known/webfinger /public.php?service=webfinger [QSA,L]
RewriteRule ^\.well-known/nodeinfo /public.php?service=nodeinfo [QSA,L]
RewriteRule ^\.well-known/carddav /remote.php/dav/ [R=301,L]
RewriteRule ^\.well-known/caldav /remote.php/dav/ [R=301,L]
RewriteRule ^remote/(.*) remote.php [QSA,L]
RewriteRule ^(?:build|tests|config|lib|3rdparty|templates)/.* - [R=404,L]
RewriteCond %{REQUEST_URI} !^/\.well-known/(acme-challenge|pki-validation)/.*
RewriteRule ^(?:\.|autotest|occ|issue|indie|db_|console).* - [R=404,L]
Let's take the first rule:
RewriteRule ^\.well-known/host-meta /public.php?service=host-meta [QSA,L]
Following my assumption (the rule is defined in a .htaccess in /var/www/nextcloud, so /var/www/nextcloud/ is stripped), the pattern '^\.well-known/host-meta' is matched again the filesystem "below" the .htaccess.
But there is no folder ".well-known.
And the other rules: there are no folders remote/, no folder or file named build, tests, config, lib, ...
Then all these rules wouldn't make sense !?!
I thought i got it, but now i'm completely stunned.
Can someone bring light into it ? Is my understanding wrong, that in per-directory context the pattern is matched against the fs ? Although the doc says it ?
Thanks.
Bernd
Helmholtz Zentrum München
Helmholtz Zentrum Muenchen
Deutsches Forschungszentrum fuer Gesundheit und Umwelt (GmbH)
Ingolstaedter Landstr. 1
85764 Neuherberg
www.helmholtz-muenchen.de
Aufsichtsratsvorsitzende: MinDir.in Prof. Dr. Veronika von Messling
Geschaeftsfuehrung: Prof. Dr. med. Dr. h.c. Matthias Tschoep, Kerstin Guenther
Registergericht: Amtsgericht Muenchen HRB 6466
USt-IdNr: DE 129521671
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org
Re: [users@httpd] some questions to mod_rewrite
Posted by Daniel Ferradal <df...@apache.org>.
Hey Bernd,
I remember my first head scratches with regex, they can be so
confusing and difficult to understand.
Although I remember preciously the day https://regexone.com/ opened my
eyes. It just took me 45 minutes to understand the basics of it.
I dearly recommend you to do the same and visit the site, once you
grasp it, regex will be tones of times easier to deal with.
Cheers
El mar, 15 dic 2020 a las 17:42, Lentes, Bernd
(<be...@helmholtz-muenchen.de>) escribió:
>
>
> ----- On Dec 11, 2020, at 4:13 PM, Eric Covener covener@gmail.com wrote:
>
> > On Fri, Dec 11, 2020 at 10:06 AM Lentes, Bernd
> > <be...@helmholtz-muenchen.de> wrote:
> >>
> >> ----- On Dec 9, 2020, at 6:02 PM, Eric Covener covener@gmail.com wrote:
> >>
> >> Hi Eric,
> >>
> >> thanks for your answer.
> >> Now i'm struggling with RewriteRule
> >> ^(?:build|tests|config|lib|3rdparty|templates)/.* - [R=404,L]
> >>
> >> Most is clear. The content of the parentheses () like build, tests .. is
> >> or-conjuncted by the pipe |,
> >> so only one of the patterns must appear.
> >> But what is ?: ?
> >
> > It makes the () "non-capturing" meaning if you had other () sequences
> > this or-conjunction would not eat up $1.
> > In the case above it is unnecessary since there is no other capture.
> >
> >> The question mark normally is a repeater for the prior character. But there is
> >> no one.
> >> And wherefore is the colon ?
> >
> > It's a special case when following "(". It allows the
> > matching/capturing to be customized a few different ways (man
> > pcresyntax has a concise list of the flags that follow "(?")
> >
> >> I gave https://perldoc.perl.org/perlre#Metacharacters a chance. It seems the ?:
> >> says that a match for (build|tests|config|lib|3rdparty|templates)
> >> can't be used as a backreference. Right ? Where is the purpose of that ?
> >
> > yes, just to avoid eating up $1. But some people do it out of habit
> > when they use () just to group "|".
> >
> >
> >> in my error_log with setting "LogLevel info rewrite:trace2":
> >> [Fri Dec 11 15:44:50.666869 2020] [rewrite:trace1] [pid 3408]
> >> mod_rewrite.c(483): [client 146.107.126.166:57329] 146.107.126.166 - -
> >> [nc-mcd.helmholtz-muenchen.de/sid#7f9158e4f700][rid#7f9155a2a0a0/initial]
> >> [perdir /var/www/nextcloud/] pass through /var/www/nextcloud/
> >>
> >> What is sid and rid ?
> >
> > server (vhost) id and request id i believe. Usually not so useful.
> > The /initial meant it's not a "subrequest" (a way apache modules
> > sometimes make an internal request related to the real request to
> > probe for things)
> >
>
> Hi,
>
> some more questions:
>
> 1. What is if a rule matched and a substitution occured ? When there are following rules, they are compared with the substitution, right ?
> 2. What is if a rule matched and a substitution occured ? Does Apache continues with the next rule or does it start from scratch with the first rule again ?
> 3. Let's assume we have a vhost with a conf file, and in the documentroot of the vhost a .htaccess file. In both files are RewriteRules.
> In which order are they processed ?
>
>
> Bernd
> Helmholtz Zentrum München
>
> Helmholtz Zentrum Muenchen
> Deutsches Forschungszentrum fuer Gesundheit und Umwelt (GmbH)
> Ingolstaedter Landstr. 1
> 85764 Neuherberg
> www.helmholtz-muenchen.de
> Aufsichtsratsvorsitzende: MinDir.in Prof. Dr. Veronika von Messling
> Geschaeftsfuehrung: Prof. Dr. med. Dr. h.c. Matthias Tschoep, Kerstin Guenther
> Registergericht: Amtsgericht Muenchen HRB 6466
> USt-IdNr: DE 129521671
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
>
--
Daniel Ferradal
HTTPD Project
#httpd help at Freenode
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org
Re: [users@httpd] some questions to mod_rewrite
Posted by "Lentes, Bernd" <be...@helmholtz-muenchen.de>.
----- On Dec 11, 2020, at 4:13 PM, Eric Covener covener@gmail.com wrote:
> On Fri, Dec 11, 2020 at 10:06 AM Lentes, Bernd
> <be...@helmholtz-muenchen.de> wrote:
>>
>> ----- On Dec 9, 2020, at 6:02 PM, Eric Covener covener@gmail.com wrote:
>>
>> Hi Eric,
>>
>> thanks for your answer.
>> Now i'm struggling with RewriteRule
>> ^(?:build|tests|config|lib|3rdparty|templates)/.* - [R=404,L]
>>
>> Most is clear. The content of the parentheses () like build, tests .. is
>> or-conjuncted by the pipe |,
>> so only one of the patterns must appear.
>> But what is ?: ?
>
> It makes the () "non-capturing" meaning if you had other () sequences
> this or-conjunction would not eat up $1.
> In the case above it is unnecessary since there is no other capture.
>
>> The question mark normally is a repeater for the prior character. But there is
>> no one.
>> And wherefore is the colon ?
>
> It's a special case when following "(". It allows the
> matching/capturing to be customized a few different ways (man
> pcresyntax has a concise list of the flags that follow "(?")
>
>> I gave https://perldoc.perl.org/perlre#Metacharacters a chance. It seems the ?:
>> says that a match for (build|tests|config|lib|3rdparty|templates)
>> can't be used as a backreference. Right ? Where is the purpose of that ?
>
> yes, just to avoid eating up $1. But some people do it out of habit
> when they use () just to group "|".
>
>
>> in my error_log with setting "LogLevel info rewrite:trace2":
>> [Fri Dec 11 15:44:50.666869 2020] [rewrite:trace1] [pid 3408]
>> mod_rewrite.c(483): [client 146.107.126.166:57329] 146.107.126.166 - -
>> [nc-mcd.helmholtz-muenchen.de/sid#7f9158e4f700][rid#7f9155a2a0a0/initial]
>> [perdir /var/www/nextcloud/] pass through /var/www/nextcloud/
>>
>> What is sid and rid ?
>
> server (vhost) id and request id i believe. Usually not so useful.
> The /initial meant it's not a "subrequest" (a way apache modules
> sometimes make an internal request related to the real request to
> probe for things)
>
Hi,
some more questions:
1. What is if a rule matched and a substitution occured ? When there are following rules, they are compared with the substitution, right ?
2. What is if a rule matched and a substitution occured ? Does Apache continues with the next rule or does it start from scratch with the first rule again ?
3. Let's assume we have a vhost with a conf file, and in the documentroot of the vhost a .htaccess file. In both files are RewriteRules.
In which order are they processed ?
Bernd
Helmholtz Zentrum München
Helmholtz Zentrum Muenchen
Deutsches Forschungszentrum fuer Gesundheit und Umwelt (GmbH)
Ingolstaedter Landstr. 1
85764 Neuherberg
www.helmholtz-muenchen.de
Aufsichtsratsvorsitzende: MinDir.in Prof. Dr. Veronika von Messling
Geschaeftsfuehrung: Prof. Dr. med. Dr. h.c. Matthias Tschoep, Kerstin Guenther
Registergericht: Amtsgericht Muenchen HRB 6466
USt-IdNr: DE 129521671
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org
Re: [users@httpd] some questions to mod_rewrite
Posted by Eric Covener <co...@gmail.com>.
On Fri, Dec 11, 2020 at 10:06 AM Lentes, Bernd
<be...@helmholtz-muenchen.de> wrote:
>
> ----- On Dec 9, 2020, at 6:02 PM, Eric Covener covener@gmail.com wrote:
>
> Hi Eric,
>
> thanks for your answer.
> Now i'm struggling with RewriteRule ^(?:build|tests|config|lib|3rdparty|templates)/.* - [R=404,L]
>
> Most is clear. The content of the parentheses () like build, tests .. is or-conjuncted by the pipe |,
> so only one of the patterns must appear.
> But what is ?: ?
It makes the () "non-capturing" meaning if you had other () sequences
this or-conjunction would not eat up $1.
In the case above it is unnecessary since there is no other capture.
> The question mark normally is a repeater for the prior character. But there is no one.
> And wherefore is the colon ?
It's a special case when following "(". It allows the
matching/capturing to be customized a few different ways (man
pcresyntax has a concise list of the flags that follow "(?")
> I gave https://perldoc.perl.org/perlre#Metacharacters a chance. It seems the ?: says that a match for (build|tests|config|lib|3rdparty|templates)
> can't be used as a backreference. Right ? Where is the purpose of that ?
yes, just to avoid eating up $1. But some people do it out of habit
when they use () just to group "|".
> in my error_log with setting "LogLevel info rewrite:trace2":
> [Fri Dec 11 15:44:50.666869 2020] [rewrite:trace1] [pid 3408] mod_rewrite.c(483): [client 146.107.126.166:57329] 146.107.126.166 - -
> [nc-mcd.helmholtz-muenchen.de/sid#7f9158e4f700][rid#7f9155a2a0a0/initial] [perdir /var/www/nextcloud/] pass through /var/www/nextcloud/
>
> What is sid and rid ?
server (vhost) id and request id i believe. Usually not so useful.
The /initial meant it's not a "subrequest" (a way apache modules
sometimes make an internal request related to the real request to
probe for things)
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org
Re: [users@httpd] some questions to mod_rewrite
Posted by "Lentes, Bernd" <be...@helmholtz-muenchen.de>.
----- On Dec 9, 2020, at 6:02 PM, Eric Covener covener@gmail.com wrote:
Hi Eric,
thanks for your answer.
Now i'm struggling with RewriteRule ^(?:build|tests|config|lib|3rdparty|templates)/.* - [R=404,L]
Most is clear. The content of the parentheses () like build, tests .. is or-conjuncted by the pipe |,
so only one of the patterns must appear.
But what is ?: ?
The question mark normally is a repeater for the prior character. But there is no one.
And wherefore is the colon ?
I gave https://perldoc.perl.org/perlre#Metacharacters a chance. It seems the ?: says that a match for (build|tests|config|lib|3rdparty|templates)
can't be used as a backreference. Right ? Where is the purpose of that ?
in my error_log with setting "LogLevel info rewrite:trace2":
[Fri Dec 11 15:44:50.666869 2020] [rewrite:trace1] [pid 3408] mod_rewrite.c(483): [client 146.107.126.166:57329] 146.107.126.166 - -
[nc-mcd.helmholtz-muenchen.de/sid#7f9158e4f700][rid#7f9155a2a0a0/initial] [perdir /var/www/nextcloud/] pass through /var/www/nextcloud/
What is sid and rid ?
Thanks.
Bernd
Helmholtz Zentrum München
Helmholtz Zentrum Muenchen
Deutsches Forschungszentrum fuer Gesundheit und Umwelt (GmbH)
Ingolstaedter Landstr. 1
85764 Neuherberg
www.helmholtz-muenchen.de
Aufsichtsratsvorsitzende: MinDir.in Prof. Dr. Veronika von Messling
Geschaeftsfuehrung: Prof. Dr. med. Dr. h.c. Matthias Tschoep, Kerstin Guenther
Registergericht: Amtsgericht Muenchen HRB 6466
USt-IdNr: DE 129521671
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org
Re: [users@httpd] some questions to mod_rewrite
Posted by Eric Covener <co...@gmail.com>.
On Wed, Dec 9, 2020 at 11:35 AM Lentes, Bernd
<be...@helmholtz-muenchen.de> wrote:
>
> Hi,
>
> i just setup a Nextcloud instance in conjunction with OnlyOffice.
> NC makes heavy use of mod_rewrite and i try to understand it.
> mod_rewrite isn't easy, so i have some questions and hope for help:
>
> 1. Is a RewriteCond just valid for the consequent rule or for all consequent rules ?
just the 1 next rule
> 2. Example: "RewriteRule ^core/js/oc.js$ index.php [PT,E=PATH_INFO:$1]"
> Are Backreferences also in flags possible ?
yes
> What is the content of $1 ? I thought backreferences belong to parts of the pattern which are in parentheses ?
> There are no parentheses.
Looks wrong due to no parens. Likely returns an empty string.
> 3. Example: RewriteCond %{REQUEST_FILENAME} !\.(css|js|svg|gif|png|html|ttf|woff2?|ico|jpg|jpeg|map|webm|mp4|mp3|ogg|wav)$
> The ! (exclamation mark) stands for a negotiation. Does that mean this condition is only fullfilled if the file does NOT have an extension
> like .css, .js ... ?
yes, it negates the regex. Doing it outside the regex can make many
patterns simpler.
> 4. Example: RewriteRule .* - [env=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
> What does this rule do ?
> All requests (.*) aren't substituted (-). But ... an environment variable HTTP_AUTHORIZATION is set to ... ?
> What means %{HTTP:Authorization} ? Is that also a kind of a backreference ?
the environmment variable is set to the value of the Authorization
request header.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org