I need to redirect some WordPress uploads folders and leave others alone. For example, I need to redirect http://www.mysite.com/wp-content/uploads/2009/08/image.jpg
to http://www.mysite.com/assets/2009/08/image.jpg
.
I tried this:
RedirectMatch 301 http://www.mysite.com/assets/2009/08/(.*)$ http://www.mysite.com/wp-content/uploads/2009/08/$1
I am using RedirectMatch
for other redirects and they are working so RedirectMatch
is enabled.
I am not sure what I am missing.
Thanks for any help.
Protocol and hostnames don’t go into the match in the
RedirectMatch
directive. It only matches against the URI (everything after the hostname, e.g./wp-content/uploads/2009/08/image.jpg
). Also, since you are redirecting to the same site, you don’t need thehttp://www.mysite.com
in your target either:But the question you’re asking is:
Which would mean you’ve got the 2 things backwards if you want to go from wp-content to assets. You’d need to swap them:
Or you can be even more general: