0
votes

My old blog was at www.example.com/myblog I changed my server and I want to use www.example.com/blog

To do this I used htaccess code Redirect 301 /myblog http://www.example.com/blog

This helped in redirecting the blog home page and individual blog posts.

The images were put in a folder named myblog in the new server. So the image url is www.example.com/myblog/wp-content/uploads/2010/04/something.jpg

But the htaccess I wrote above redirects this to www.example.com/blog/wp-content/uploads/2010/04/something.jpg which returns 404.

Can anyone help me to write htaccess code for redirecting blog post urls only excluding the blog image urls?

1

1 Answers

0
votes

Instead of using mod_alias and the Redirect directive, try mod_rewrite and add some conditions:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?myblog/(.*)$ http://www.example.com/blog/$1 [L,R=301]

# redriect the index
RewriteRule ^/?myblog/?$ http://www.example.com/blog/ [L,R=301]