Welcome to WebmasterWorld Guest from

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Exclude image urls from redirection

6:46 am on Sep 26, 2012 (gmt 0)

Junior Member

Top Contributors Of The Month

joined:Sept 26, 2012
posts: 47
votes: 0


This is my first post on Webmasterworld..!

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?
9:34 am on Sept 26, 2012 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month

joined:Apr 9, 2011
votes: 244

You can't do it with mod_alias (Redirect by that name). But it is very easy in mod_rewrite, because all you have to do is constrain your redirects to file names ending in something other than jpg/gif etc. In fact most redirects should be constrained by ending-- usually / or html or equivalent. Saves work for the server, since humans rarely ask for images by name.

And now you can start poring over past threads in this Forum :) Do your page URLs end in html or php or similar, or no extension at all?
9:49 am on Sept 26, 2012 (gmt 0)

Junior Member

Top Contributors Of The Month

joined:Sept 26, 2012
posts: 47
votes: 0

No the urls have no extension. Will this help solve this problem

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

Will this exclude images from redirection. That's my requirement