I'm configuring Redirects from a Html static website to Wordpress, I'm doing it manually in the .htaccess file and for some other rules I'm using Redirection plugin

I have added these rules to my .htaccess:

  <IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /wordpress/
RewriteCond %{THE_REQUEST} (\.htm|\.html)
RewriteRule ^(.*)(\.htm|\.html)$ http://www.mywebsite.com/wordpress/$1 [R=301,L]

They work fine redirecting old html documents to the new wordpress installation without file extension.

I have problems trying to add the needed redirection for images. I have tried adding this rule but I get redirection loop when I try to access .jpg files:

 RewriteCond %{THE_REQUEST} \.jpg
    RewriteRule ^(.*\.jpg)$ /wordpress/wp-content/uploads/2016/02/$1 [R=301,L]

# BEGIN WordPress
<IfModule mod_rewrite.c>

How can I do it correctly?


If your images were in a subdirectory such as images the solutions is simple

RewriteRule ^/images/(.*\.jpg)$ wordpress/wp-content/uploads/2016/02/$1 [R=301,L]

If the images are in random locations or in the root.

RewriteCond %{REQUEST_URI} !^/wordpress/wp-content/uploads/
RewriteRule ^(.*\.jpg)$ /wordpress/wp-content/uploads/2016/02/$1 [R=301,L]

The point is, your RewriteRule is matching again after you redirect into the wordpress directory. (It matches ANY jpg). You have to find a way to NOT match the new wordpress based files.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.