I'd make it
^((?:[^/]+/)*)([^/.]+)
or simply (omitting the open-and-close parentheses since they're not needed for separate captures)
^(([^/]+/)*[^/.]+)
to avoid generating a superfluous $2 that you then have to keep track of. Or does Apache's dialect of RegEx not do nested captures?
Actually, I am not removing the -p, I was just thinking it was a good place to "anchor the search" (if that's a term anyone has ever used).
Oh, that's fine, just include it in your capture then. You really are lucky to have a unique search string. But you can't simply have
(.+-p.+)
changing to
shop/$1
because you have to allow for users who were here yesterday and bookmarked the address
with the "shop/" piece, so you don't end up with your server frantically looking for
shop/shop/shop/shop/blahblah-p/blahblah...
:)
In English, what you want to do is:
If the original address contains "-p" but does not start with "shop/", then add "shop/".
Does it have to be a redirect or can you use rewrite instead? It then becomes easier to lay out the conditions. I
think (g1? you out there?) it goes like this:
RewriteCond %{REQUEST_URI} !^shop/
RewriteCond %{REQUEST_URI} -p
RewriteRule (.+\.html) shop/$1 [R=301,L]
In English:
IF your user requests a page which
does not (! means no)
begin with (^ means beginning)
"shop/" AND (groups of rules carry an implied "and" unless you specify [OR])
does contain (if you don't have any anchors, the text just has to be in there somewhere) the element
-p THEN
grab their whole request (the part you put in parentheses), shove a "shop/" in front, and put back the original request
AND ALSO
make it a 301 Redirect (if you don't have the R=301 piece, the user will physically end up at the right page but their browser's address won't change, and search engines won't know that you've moved)
AND FINALLY
proceed directly to the page and don't waste any more time on the .htaccess page (if you leave out the L, the code will continue looking for any other rules that might apply)
except that I may have put the / on the wrong side of "shop"