<p>There doesn't seem to be much info on this topic so I'm going to outline my specific problem then maybe we can shape the question and the answer into something a bit more universal.</p>

<p>I have this rewrite rule</p>

<pre><code>RewriteEngine On
RewriteBase /bookkeepers/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/?$ index.php?franchise=$1
</code></pre>

<p>Which is changes this URL</p>

<pre><code>http://example.com/location/kings-lynn
</code></pre>

<p>Into this one</p>

<pre><code>http://example.com/location/index.php?franchise=kings-lynn
</code></pre>

<p>The problem I am having is that if I add a trailing slash</p>

<pre><code>http://example.com/location/kings-lynn/
</code></pre>

<p>then the query string is returned as</p>

<pre><code>franchise=kings-lynn/
</code></pre>

<p>and for some reason none of my CSS and Javascript files are being loaded.</p>

<p>Any ideas?</p>

It looks like the (.+) is being greedy matched.  In that case, you could try
```
```
RewriteRule ^(.+[^/])/?$ index.php?franchise=$1
```
```
This makes sure that the first group (in the brackets) doesn't end in a slash.