: How can I use .htaccess to make old link retrieve content from new location? One of my sites had a WordPress site in the subdirectory (root)/blog/. Using rules in .htaccess, the site was called
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.
More posts by @Sent6035632
2 Comments
Sorted by latest first Latest Oldest Best
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/.+) [L]
ie. To remove the /blog prefix.
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.
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.