1

One of my sites had a WordPress site in the subdirectory (root)/blog/.

Using rules in .htaccess, the site was called up without the /blog/ in the URL.

I recently changed it by removing the /blog/ directory, moving all the WP content into the root.

This particular blog auto-feeds all articles to a Facebook page. Each post on FB includes an the Featured Image from the blog entry. Since changing the directory structure, none of the images from the historical posts are showing up in Facebook.

What is the correct way to use .htaccess to make

mysite.com/blog/wp-content/uploads/*

call up the respective file from

mysite.com/wp-content/uploads/*

I have tried various Rewrite rules, but the ones I tried seemed to always redirect the URL to the new one, whereas I want the old URL to directly call up the file being requested, only from the files new location (in the way an Alias would work).

The existing .htaccess content

As requested, here is existing .htaccess code

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

UPDATE: Re answer I posted to this question

I worked out how to do this with a symlink. I would still like to know how to do it correctly with the .htaccess file (using rewrite rules, etc.), because setting up the symlink required SSH access, and I usually don't have SSH access to my sites.

  • It would help to see what .htaccess code you have. – closetnoc Jan 20 '16 at 3:39
  • Another thought may be to use a symlink from /blog/wp-content/uploads/ to /wp-content/uploads/. – closetnoc Jan 20 '16 at 3:40
  • The current .htaccess code is just the default for Wordpress. I'll add it to the question. – inspirednz Jan 20 '16 at 3:57
  • I did try setting up a symlink, but it didn't work. I am not sure why. Perhaps Apache is not configured to follow symlinks, or perhaps I didn't create it correctly. It's a shared server, so I have no access to Apache config files. I do have shell access, which is what I used to set up failed symlink. – inspirednz Jan 20 '16 at 4:01
  • Try adding Options +FollowSymLinks in the top of the .htaccess file. This option may not be turned on by the host. – closetnoc Jan 20 '16 at 4:39
2

Facebook would have been using the image URL as specified in the open graph tags. Since (by the sounds of it) the URL structure wasn't actually changed in WP (only in .htaccess) then this would have contained the /blog subdirectory in the URL. But then presumably you had to make an exception in .htaccess for the /blog/wp-content/uploads/ directory, or was FB following the redirect? Anyway...

To internally rewrite requests for /blog/wp-content/uploads/... to /wp-content/uploads/... you can try adding the following immediately after the RewriteBase directive (ie. before the main WP directives):

RewriteRule ^blog(/wp-content/uploads/.+) $1 [L]

ie. To remove the /blog prefix.

1

I tried doing this with a symlink, and it failed. After closetnoc also suggested I could use a symlink, I looked at it further.

What worked was the following command (using SSH, at [~/public_html]#):

mkdir blog
mkdir /blog/wp-content
ln -s ~/public_html/wp-content/uploads ~/public_html/blog/wp-content/uploads

I would still like to know the correct way to do this with .htaccess. I don't have SSH access on most of my sites, so the above solution would not work on those sites.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.