homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

Exclude image urls from redirection

Msg#: 4500044 posted 6:46 am on Sep 26, 2012 (gmt 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?



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

Msg#: 4500044 posted 9:34 am on Sep 26, 2012 (gmt 0)

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?


Msg#: 4500044 posted 9:49 am on Sep 26, 2012 (gmt 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

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved