使用htaccess将其他域图片加载到我的域中? [英] Load another domain images to my domain using htaccess?

查看:52
本文介绍了使用htaccess将其他域图片加载到我的域中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2个域和2个服务器 example.com example2.com .例如: example.com 是我的主要域名.我将网站图片上传到 example2.com

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

我当前的图像路径http://example.com/data/photos/sample.jpg.
但我的所有图片都在http://example2.com/data/photos/sample.jpg

my current image path http://example.com/data/photos/sample.jpg.
but my all images are in http://example2.com/data/photos/sample.jpg

所以我创建htaccess 301 重定向

So i create htaccess 301 redirect

RewriteEngine on
RewriteBase /
RewriteRule ^data/photos/(.*)$ http://example2.com/data/photos/$1 [R=301]

但是它对我不起作用.因为我在我的所有页面中都调用了完整的URL.所以任何一个建议对我都很有帮助

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

已更新我的旧Htaccess文件

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>

推荐答案

您需要重新排列规则.您最终的htaccess应该看起来像

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>

这篇关于使用htaccess将其他域图片加载到我的域中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆