homepage Welcome to WebmasterWorld Guest from 54.204.182.118
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
301 for one image ?
Dexie

10+ Year Member



 
Msg#: 4209796 posted 8:51 am on Oct 1, 2010 (gmt 0)

Hi all, had to change one image for another, how do I do a 301 for this please ?

Any help appreciated.

Dexie

 

sublime1

10+ Year Member



 
Msg#: 4209796 posted 12:52 pm on Oct 1, 2010 (gmt 0)

Hi Dexie --

The usual route is to add a RewriteRule to the .htaccess file in the web root of your server, although there are at least several hundred other ways to do it depending on a lot of things.

Could you provide some additional information, including what platform you're using, what application you're doing this for, what you have tried already, and so forth.

If your server is Apache, here's a link to the rewriting guide [httpd.apache.org...] (actually, it's a link to the guide even if your server isn't apache ... but perhaps more relevant to you if your server is apache :-)

Thanks

Tom

jdMorgan

WebmasterWorld Senior Member jdmorgan us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4209796 posted 1:07 pm on Oct 1, 2010 (gmt 0)

Use mod_rewrite's RewriteRule directive, or use mod_dir's Redirect or RedirectMatch directives.

Please see the resources cited in our Apache Forum Charter and the examples and tutorials posted in our Apache Forum Library. If you have any difficulty, please post your best-effort attempt at coding a solution, along with your test procedure and test results for discussion.

Thanks,
Jim

Dexie

10+ Year Member



 
Msg#: 4209796 posted 12:11 pm on Oct 3, 2010 (gmt 0)

Many thanks Jim and sublime, it's appreciated. I did look through the links and have googled this till my fingers were sore, but still no luck.

Am trying

Redirect 301 /old_image.jpg /new_image.gif

but get a 500 internal server error

Am on Apache

Any help much appreciated.

sublime1

10+ Year Member



 
Msg#: 4209796 posted 5:09 pm on Oct 3, 2010 (gmt 0)

Dexie --

There is no such apache directive "Redirect", which would explain the server error. Perhaps you're looking for "RewriteRule", something like

RewriteRule ^/old_image\.jpg$ /new_image.gif [R=301,L]

could potentially be along the lines of what you want. But there are a lot of other things to know. Apache rewriting is powerful, but also very complicated and obtuse.

Hope this gets you on the right path...

Tom

g1smd

WebmasterWorld Senior Member g1smd us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4209796 posted 5:50 pm on Oct 3, 2010 (gmt 0)

Redirect and RedirectMatch do indeed exist, but RewriteRule is usually a better way to do things.

The redirect target should include the domain name.

Dexie

10+ Year Member



 
Msg#: 4209796 posted 10:16 am on Oct 4, 2010 (gmt 0)

Many thanks Tom and g1smd - it's appreciated. One thing, why would there be a \ before the .jpg ?

RewriteRule ^/old_image\.jpg$ /new_image.gif [R=301,L]

sublime1

10+ Year Member



 
Msg#: 4209796 posted 12:49 pm on Oct 4, 2010 (gmt 0)

g1smd -- thanks for the correction -- you're right about those directives.

Dexie --

The second argument to RewriteRule (or RedirectMatch which I have now looked up) is a regular expression. Search "regular expressions" for more. (Warning: Regular expressions are a little joke played on people who have to make computers work in order to make us humble and feel unworthy. They are, however, a necessary evil.)

Various characters are used to form regular expressions, including the "." which means "a character" in regex patterns. If you want the pattern to match only on a period, you need to escape it with a backslash.

Without the escape, the pattern would also match "/old_imageXjpg" as well as "/old_image.jpg".

The ^ means that the match must start with the characters specified, and the $ means that it must end with the characters specified.

Without ^ and $, "/something/else/old_image.jpgsareimagefiles" would also match.

In short, they are they make sure your pattern matches exactly, and only, what you want.

jdMorgan

WebmasterWorld Senior Member jdmorgan us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4209796 posted 2:50 pm on Oct 4, 2010 (gmt 0)

Our Apache Forum Charter has a link to a concise regular-expressions tutorial and to the Apache mod_rewrite documentation. Proceeding to change your server configuration (which is what server config and .htaccess do) without reviewing those documents can be very harmful to the operation of your site and to its search rankings...

The example code previously posted is for use in a server config file outside of any <Directory> containers. For use in .htaccess or in server config file within a <Directory> container, remove the leading slash from the RewriteRule pattern. This caveat is necessary whenever it is not made clear where the code is to be placed.

Jim

g1smd

WebmasterWorld Senior Member g1smd us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4209796 posted 7:43 pm on Oct 4, 2010 (gmt 0)

The redirect target should include the domain name.

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