I have a blog installed in http://www.foo.com/wp/ and would like all requests that go to any page that doesn’t start with /wp/ to be redirected to http://www.foo.com/wp/ (without preservation of the URL).
E.g.:
www.foo.com/bar/baz/hello.gif > www.foo.com/wp/
Also, at the same time, I need the URL to have www. added if it doesn’t (which might be where my rules are getting confused)
At the moment, I have:
RewriteCond %{HTTP_HOST} !^www.foo.com [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^/(.*) http://www.foo.com/$1 [R=permanent]
RewriteRule ^(?!wp)/(.*)$ http://%{HTTP_HOST}/wp/($2) [R=permanent]
But I think this is currently completely broken.
Help much appreciated.
.*.(?!)is not a capturing construct, and you substitute in captured patterns by writing$1, not($1).Edit: Apparently for OP the last rule doesn’t work, failing to exclude the cases that begin with
/wp/, which makes no sense to me but whatever. Here’s an attempt at a workaround: