1

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/(.*)$ /$1;
    }

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

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?

3

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(/.*)$ $1$2;

Explanation: you need to capture everything before ($1) and after ($2) 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,}(/.*?)$" $1/civicrm$2;

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.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.