简体   繁体   中英

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:

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

Output:

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

Desired output:

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. 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

Thanks everyone who replied on the comments.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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