Question: I have a programmatically generated set of rules for a site like this:

```
RewriteEngine on
RewriteRule ^abc/?(.*)$ /$1?organisation=abc [QSA,L]
RewriteRule ^fghij/?(.*)$ /$1?organisation=fghij [QSA,L]
RewriteRule ^fghijklmn/?(.*)$ /$1?organisation=fghijklmn [QSA,L]

```

So that our client can set up multiple minisites on their domain for various clients of their own.
Because the url could end in / or /blah.php I've created the rules as above but this means the RewriteEngine would stop after ^fghij/?(.*)$ and never find ^fghijklmn/?(.*)$
How could I rewrite my rules so every organisation is properly matched?
Many thanks in advance

Answer: 
Your regex seems to be a problem since `^fghij/?(.*)$` would also match `fghijklmn`.

Try this code:

```
RewriteEngine on
RewriteRule ^abc(/.*)?$ $1?organisation=abc [QSA,L]
RewriteRule ^fghij(/.*)?$ $1?organisation=fghij [QSA,L]
RewriteRule ^fghijklmn(/.*)?$ $1?organisation=fghijklmn [QSA,L]

```
I think that the /? in ^abc/?(.\*)$ is saying optionally match / then match anything else after it so you likely want something like

```
RewriteRule ^abc//?(.*)$ /$1?organisation=abc [QSA,L]

```

That will enforce a / at the end since you say the URL will always end in / or /blah.php

Also, I am unsure why you don't just try to match the organisation with a non-greedy matcher on the word before the first slash and then append it to the query string instead of creating it manually.