Reputation: 523
Hello I am trying to 301 redirect any and all subdirectories of a parent directory , but NOT have the parent directory index itself be redirected
Here's what I currently have
RewriteEngine On
RewriteRule ^parent/(.*) /newtoplevel/parent/$1 [R=301,NC,L]
The above code seems to work fine, but unfortunately for my use it also redirects the original parent index to the new. For example if I load http://example.com/parent/ it will redirect to http://example.com/newtoplevel/parent/ which is NOT what I need...
I only want the various /parent/subdirectory/ to redirect to /newtoplevel/parent/subdirectory
While making sure that /parent/index.html ( http://example.com/parent/ ) does NOT redirect
Upvotes: 2
Views: 386
Reputation: 12438
If you want only the subdirectories (parent/.../
) of parent
to be redirected (and keeping the sub-trees as-is) then you should use the following regex:
^parent/(.+/.+)
Tested on regex101: https://regex101.com/r/gv6ZUf/4
Upvotes: 1