Redirect directory and contents using htaccess

How to redirect an entire directory and all internal files using the htaccess file.

In the example below the site moved from a standard static page website to a site powered by WordPress, and thus moved its images directory as shown below:

http://www.example.com/images/

http://www.example.com/wp-content/uploads/

(note: In WordPress, change your media settings by un-checking this box “Organize my uploads into month- and year-based folders”. This will keep all your uploads in a single folder.)

RewriteEngine On
RewriteRule ^images/(.*)$ http://www.example.com/wp-content/uploads/$1 [L]

Comments

  1. trau says

    hi! very congratulation for this blog! very interesting! :)
    i have a question about this post..

    I would use your code for redirect my images into my WP blog from folder wp-contet/uploads to bucket in s3 of amazon and so another domain with same sub folder (importa same sub folder)

    example:
    FROM:
    http://my-site.it/wp-content/uploads/2010/09/aaa.jpg

    TO:
    http://my-bucket.s3.amazonaws.com/2010/09/aaa.jpg

    this is my htaccess:

    RewriteEngine On
    RewriteRule ^/wp-content/uploads/(.*)$ http://MY-BUCKET.s3.amazonaws.com/$1 [L]

    # BEGIN WordPress

    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]

    # END WordPress

    But redirect image to s3 dont work :((
    PS pubblic url of image in s3 is good in a new browser :)

    where i wrong?
    sorry my bad english :)

    can you help me with rule in htaccess please?? :))
    thank you
    erwin

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>