简体   繁体   English

使用htaccess RewriteRule重定向到完整URL

[英]Redirect to full URL with htaccess RewriteRule

I want to load images from production website if they don't exist on my local environment, for that, I have this htaccess rule: 如果本地环境中不存在图像,我想从生产网站加载图像,为此,我有以下htaccess规则:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule uploads/(.*)$ http://www.productionserver.com/uploads/$1 [R=302,L,NC]

The problem: 问题:

Original URL: 原始网址:

http://localhost:8080/myproject/uploads/image.jpg http:// localhost:8080 / myproject / uploads / image.jpg

Output: 输出:

http://localhost:8080/myproject/http://www.productionserver.com/uploads/image.jpg http:// localhost:8080 / myproject / http://www.productionserver.com/uploads/image.jpg

Desired output: 所需的输出:

http://www.productionserver.com/uploads/image.jpg http://www.productionserver.com/uploads/image.jpg

What must I change in order to achieve that? 为了达到这个目的,我必须改变什么?

The code was correct. 代码正确。

I moved it to the top of my .htaccess file and it worked. 我将其移至我的.htaccess文件的顶部,它可以正常工作。 Some other rule was interfering with it. 其他一些规则正在干扰它。

I believe the tool I was using to debug the "Output" was wrong. 我相信我用来调试“输出”的工具是错误的。 The tool is: http://htaccess.madewithlove.be 该工具是: http : //htaccess.madewithlove.be

Thanks everyone who replied on the comments. 感谢大家对评论的答复。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM