Reputation: 835
I'm trying to make my PHP site pull images in /assets/u/ from another server using a redirect in the .htaccess file. The .htaccess is definitely being used. I know because I set 'AllowOverride All' in the sites root directory in HTTPD config and even tested it by putting in incorrect syntax on purpose and confirming that I get an internal server error. But my images in /assets/u/ still aren't being pulled from the other server. Below is my .htaccess file...
SetEnv APPLICATION_ENV production
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^((www)|(draft))\.
RewriteRule ^(.*?)\/*$ http://www.%{HTTP_HOST}/$1 [R=301,L]
# Start of attempted redirect #
RewriteCond %{REQUEST_URI} ^.*(/assets/u/).*$ [NC]
RewriteRule ^assets/(.*)$ http://assets.otherserver.com/$1 [L,R=301]
# End of attempted redirect #
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
Upvotes: 1
Views: 800
Reputation: 7476
I don't fully understand your question but here is my 1st attempt.
I am assuming you are using assets/u/
as link in <img href="assets/u/test.jpg">
tag, and your actual files are stored in http://assets.otherserver.com
address,
For this task I suggest you to use mod_proxy
to display your images without redirecting the urls try with below rule I am assuming you are able to arrange your .htaccess without breaking the other rules.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^/assets/u/(.+?)$
RewriteRule ^ http://assets.otherserver.com/%1 [P,L]
For above rule to work you must have enabled below.
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule proxy_module modules/mod_proxy.so
Uncomment above lines in httpd.conf.
Inform me of any update.
Upvotes: 2
Reputation: 6288
As you use RewriteBase
Directive, try to remove the the first /
RewriteCond %{REQUEST_URI} ^(assets/u/).*$ [NC]
Upvotes: 0