Umair Ayub
Umair Ayub

Reputation: 21201

Rewrite image directory to another folder in server using htaccess

I have images in

/home/crawler/scrapers/images/website

for example

/home/crawler/scrapers/images/website/1/img-name.jpg

My Apache root is at

/var/www/html

I have .htaccess in this folder with following content

RewriteEngine On
RewriteRule ^/images/(.*)$ /home/crawler/scrapers/images/$1 [R,L]

My goal is to show images from the images folder as I mentioned above.

http://website.com/images/website/1/img-name.jpg   >>  /home/crawler/scrapers/images/website/1/img-name.jpg

Currently I am getting

Not Found

The requested URL /home/crawler/scrapers/images/website/1/img-name.jpg was not found on this server.

Apache/2.4.18 (Ubuntu) Server at IP Port 80

PS: I confirm that hataccess is enabled.

Upvotes: 2

Views: 1152

Answers (1)

anubhava
anubhava

Reputation: 784898

You can use Alias directive for this.

Include following code in your vhosts.conf or httpd.conf and restart Apache.

Alias /images /home/crawler/scrapers/images
<Directory /home/crawler/scrapers/images>
   Allow from all
</Directory>

Upvotes: 3

Related Questions