John Christian De Chavez John Christian De Chavez - 1 month ago 7
Apache Configuration Question

htaccess for new image folder

I'm trying to rewrite the url to another url.

because i already made a subdomain for my images and i want all the url requesting for my images should get in the new image domain.

for example.

old image link - http://www.website.com/uploaded/art/sd.jpg
should get to - http://img.website.com/uploaded/art/sd.jpg

another one

old image link - http://www.website.com/uploaded/photo/ss.jpg
should get to - http://img.website.com/uploaded/photo/ss.jpg

i have my subfolders in my uploaded folder.
here is my htaccess for now and it seems i cant get it to work.

RewriteEngine on
RewriteRule ^uploaded/(.*)$ http://img.website.com/uploaded/$1 [R=301,L]

# Use PHP5.4 as default
#AddHandler application/x-httpd-php54 .php

<IfModule mod_rewrite.c>


RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]

RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [QSA,L,NC]

</IfModule>
<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 1 day"
ExpiresByType text/css "access plus 18000 seconds"
ExpiresByType text/plain "access plus 1 month"
ExpiresByType text/javascript "access plus 1 month"
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
ExpiresByType application/x-javascript "access plus 1 month"
ExpiresByType application/javascript "access plus 18000 seconds"
ExpiresByType application/x-icon "access plus 1 year"
</IfModule>


this htaccess is saved to my public html folder. main root of my website.

Answer

Create an htaccess in the /uploaded folder and add the following redirect :

Redirect 302 /uploaded/ http://img.website.com/uploaded/

This will redirect all requests from /uploaded folder to the new destination, eg : example.com/uploaded/foobar to http://img.website.com/uploaded/foobar .

You change the redirect status to 301 (permanent redirect) when you are sure it's working ok.