.htaccess redirects images from the old folder to the new folder

I just switched from Drupal + Wordpress to a site fully integrated in WordPress.

Well, I have a set of images where the files no longer exist, and you need to try to save all the images in one folder (if possible). Need to send requests for any gif | png | jpg that for http://www.domain.com/blog/wp-content/uploads/ at http://www.domain.com/wp-content/uploads .

If someone can help, it will be appreciated - my .htaccess, what it was. thanks in advance

+6
.htaccess
source share
5 answers

If you google for "htaccess redirect", the top link is: http://www.htaccessredirect.net/

If you use the "301 Redirect Directory" section, you get this code:

//301 Redirect Entire Directory RedirectMatch 301 /blog/wp-content/uploads/(.*) /wp-content/uploads/$1 

As far as I know, the target domain should be absolute, so the following may work:

 //301 Redirect Entire Directory RedirectMatch 301 /blog/wp-content/uploads/(.*) http://www.domain.com/wp-content/uploads/$1 
+9
source share

Try this rule in your .htaccess:

 RewriteEngine On RewriteRule ^/blog/wp-content/uploads/(.+)\.(png|gif|jpg)$ wp-content/uploads/$1.$2 [QSA,L] 
0
source share

try it

 RewriteEngine on RewriteCond %{HTTP_REFERER} ^http://www.domain.com/blog/wp-content/uploads [NC] RewriteRule .* http://www.domain.com/wp-content/uploads [NC,L] 
0
source share

You can try and put this

 RewriteEngine ON RewriteRule ^/blog/wp-content/(.*)$ http://newdomain.com/wp-content/$1 [R=301,L] 
0
source share

What I hated in all rewriting and redirection rules for .htaccess files, they all rely on the hardcoding path (URI) and / or server for redirection.

The dot ".htaccess" will be files, it should be for the current directory! It can be referenced in several ways, installed on different servers in different places. Thus, trying to move it to a specific location to simply rename directories is illogical.

The solution is to somehow include the current URI (no matter where the .htaccess location is ...)

This is my current solution for location-independent ".htaccess" redirects for a renamed subdirectory, and even I admit that this is not perfect ... BUT IT WORKS ...

 Options +FollowSymLinks RewriteEngine On RewriteRule ^OLDdir/.*$ %{REQUEST_URI}::: [C] RewriteRule ^(.*)/OLDdir/(.*)::: $1/NEWdir/$2 [R,L] 
0
source share

All Articles