I am newby in htaccess, please help if you can. My task is simple, I think.
I have a website, for example newsite.com. It was made on wordpress. And I have old copy of this site, on other domain, for example oldsite.com.
When I transfered files from oldsite to newsite some of pictures didn't transferred to newsite, but they still exists on oldsite.
Now when pages are loading I checking post thumbnails on newsite, and if they don't exists on newsite, I am replacing newsite url to oldsite url.
But is there any ways to not just replace newsite.com/image.jpg to oldsite.com/image.jpg, but replace newsite.com/image.jpg, to, for example newsite.com/imgs/image.jpg, and in .htaccess file make rule that if url has /imgs/ part, it means that need to look for image in oldsite.com/image.jpg
I think you can do it by below .htaccess code
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^OLDDOMAIN\.com$ [NC]
RewriteRule ^(.*)$ http://NEWDOMAIN.com [R=301,L]
In your new site HTML code
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ([^.]+\.(jpe?g|gif|bmp|png))$ http://www.newurl.com/imgs/$1 [R=301,L,NC]
You can put this configuration in the file of virtualhost.
<VirtualHost *:80>
ServerName example.org
DocumentRoot /srv/redireccion
Redirect permanent / https://example2.org/
</VirtualHost>