Hi all, had to change one image for another, how do I do a 301 for this please ?
Any help appreciated.
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 :-)
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.
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.
Redirect 301 /old_image.jpg /new_image.gif
but get a 500 internal server error
Am on Apache
Any help much appreciated.
5:09 pm on Oct 3, 2010 (gmt 0)
There is no such apache directive "Redirect", which would explain the server error. Perhaps you're looking for "RewriteRule", something like
g1smd -- thanks for the correction -- you're right about those directives.
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.
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.
7:43 pm on Oct 4, 2010 (gmt 0)
The redirect target should include the domain name.