views:

116

answers:

2

Hey Guys & Gals,

I recently moved my WordPress website to a subfolder. I want to add a redirect in the .htaccess file so that the links to images I've uploaded originally to ~/wp-content/uploads/ will pass to ~/blog/wp-content/uploads. The .htaccess file must remain in the root folder for WordPress to read it properly. This is what I tried

Redirect /wp-content/uploads/ /blog/wp-content/uploads

That worked great, except I host other domains on this account, and all of the other domain's upload folders were being redirected in a similar manner.

Is there a way to restrict this redirect to just one domain? So that example.com/wp-content/uploads redirects to example.com/blog/wp-content/uploads, but another.com/wp-content/uploads does not?

Thanks everyone!

+2  A: 

You should place the Redirect inside the <VirtualHost> definition for example.com in the httpd.conf (or equivalent) instead of .htaccess

on a sidenote, Redirectsays temporary / 302 by default, so it is nicer to use

Redirect permanent /wp-content/uploads/ /blog/wp-content/uploads instead

Kimvais
This is really the correct answer. If you have access to put the Redirect in your config file inside the correct domain-specific section then do that.
Trey
I would agree with this. Unfortunately, on this particular shared host I don't have that kind of access.
John K
+2  A: 

Assuming you want a 301 redirect, using this RewriteEngine example should work:

Options +FollowSymLinks
RewriteEngine on

RewriteCond %{HTTP_HOST} ^(www.)?example.com$ [NC]
RewriteRule ^wp-content/uploads/(.*)$ http://www.example.com/blog/wp-content/uploads/$1 [R=301,L]
Trey
There we go! This did it for me! Thanks for your help!
John K