ELIJAH MWANGI
ELIJAH MWANGI

Reputation: 21

Redirect images in .htaccess

I have two domains pointing to one application with different directories that is frontend on www.frontend.com and backend on www.backend.com. I have placed all images in the frontend/uploads folder, while on backend I cannot access the images on frontend/uploads.

How can I redirect all ^/uploads to www.frontend.com/uploads using htaccess?

I have tried this:

RewriteCond %{REQUEST_URI} ^/uploads/(.*)$
RewriteRule ^uploads/(.*)$ http://frontend.com/uploads/$1

Upvotes: 1

Views: 49

Answers (1)

arober11
arober11

Reputation: 2019

Personally I'd just use a filesystem level symbolic link, as far more efficient (Unix, Linux, BSD, Darwin {OS X}) eg.

ln -s /srv/www/frontEnd/htdocs/uploads  /srv/www/backEnd/htdocs/uploads

and make sure you have the FollowSymLinks option set in the backend Directory block eg.

<Directory /srv/www/backEnd/htdocs/uploads>
  Options Indexes FollowSymLinks
</Directory>

But assuming the www.frontend.com site is accessible to your www.backend.com users all you need in your backend config is:

RewriteRule ^/?uploads/.* http://frontend.com%{REQUEST_URI} [NC,L,R=301]

If you take this approach I'd stick the rule in the httpd.conf, rather than a .htaccess, as that file is only parsed once on server startup, and the rule compiled, rather than having to parse the file for every request.

Upvotes: 1

Related Questions