Load another domain images to my domain using htaccess?

.htaccess, apache, mod-rewrite, php, redirect

Solution

You need to reorder your rules. Your final htaccess should look something like

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    RewriteRule ^(data/photos/.*)$ http://example2.com/$1 [R=301,NC,L]

    RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
    RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?%{QUERY_STRING} [NE,L]

    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
</IfModule>

Problem

I have 2 domains and 2 servers `example.com` and `example2.com`. for eg: `example.com` is my main domain. i upload my site images into `example2.com` my current image path `http://example.com/data/photos/sample.jpg`. but my all images are in `http://example2.com/data/photos/sample.jpg` So i create htaccess 301 redirect ``` RewriteEngine on RewriteBase / RewriteRule ^data/photos/(.*)$ http://example2.com/data/photos/$1 [R=301] ``` But its not working for me. Because of i called full URL into my all pages. so any one suggestion its very helpful for me Updated my old Htaccess file ``` <IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{HTTP_HOST} ^example\.com$ [NC] RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L] RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php?%{QUERY_STRING} [NE,L] RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L] RewriteEngine On RewriteBase / RewriteRule ^data/photos/(.*)$ http://example2/data/photos/$1 [R=301] </IfModule> ```

Original source