Mobile app version of vmapp.org
Login or Join
Turnbaugh106

: Nginx location rewrite: match /{?x}, {y}, {?z}. Remove y I am trying to run CiviCRM with Drupal 7 in a docker container of my own design. Unfortunately, I am running into a problem where for

@Turnbaugh106

Posted in: #Nginx #RegularExpression #UrlRewriting

I am trying to run CiviCRM with Drupal 7 in a docker container of my own design.

Unfortunately, I am running into a problem where for some unknown reason CiviCRM is outputting resource requests malformatted. Sometimes like this ('...' conotates the rest of the path to the resource):

/... (good)
/civicrm/... (good)


Sometimes like this:

/civicrm/sitename/... (bad)


Sometimes like this:

/sitename/... (bad)


Sometimes like this:

/civicrm/sitename/civicrm (bad)


Sometimes like this:

/civicrm/sitename/civicrm/sitename/... (very bad)


And so on, possibly infinitum:

/civicrm/sitename/civicrm/sitename/civicrm/... (very bad)


Now regex's are not my forte. After much humming and harring, I have managed to produce the following:

location /civicrm/sitename {
rewrite ^/civicrm/sitename/(.*)$ /;
}

location /sitename/ {
rewrite ^/sitename/(.*)$ /;
}


Now many of the resources load better but this does not catch all of the problems. The best I can define it is this:
#If the URL contains a / followed by any characters or none followed by a / followed by sitename followed by any characters or none, remove sitename:
rewrite /(?./)sitename/(?.)$ $;
# Then continue processing the next directive. #If the rewritten URL contains /civicrm/ more than once, remove all instances of /civicrm/ then add it once:
rewrite /(?./)civicrm/civicrm/(?.)$ /civicrm/$;


Any help?

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Turnbaugh106

1 Comments

Sorted by latest first Latest Oldest Best

 

@Miguel251

If the URL contains a / followed by any characters or none followed by
a / followed by sitename followed by any characters or none, remove
sitename:


rewrite ^(.+)/sitename(/.*)$ ;


Explanation: you need to capture everything before () and after () the match, in order to construct the result.


If the rewritten URL contains /civicrm/ more than once, remove all
instances of /civicrm/ then add it once:


rewrite "^(.*?)(?:/civicrm){2,}(/.*?)$" /civicrm;


Explanation: As above, except that two or more non-capturing /civicrm strings are matched and the first and last capture are lazy. Expressions containing a { should be quoted.

Useful resource for regular expressions is here.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme