.htaccess redirect

wordpress

#1

I have a folder full of images that I want to reorganize, using .htaccess redirect to prevent broken links. Redirects apparently work on directories, but not for an individual file. That is:

Redirect 301 / http://www.panix.com/~iayork/

works in that it redirects my entire folder to my other site’s “Images” folder – as it should – but when I try to redirect a single image file thus:

Redirect 301 /Amy&William.JPG http://www.iayork.com/Images/Old_Images/Amy&William.JPG

gives me a 404 Not Found error. (The new file works fine when I go directly there.)

Am I doing something wrong? As far as I can see the syntax is correct, and I’ve tried every other plausible variant I can think of with no success.

Thanks for any suggestions.


#2

I’ve used RedirectPermanent. Is your order backwards?

http://www.webmasterworld.com/forum92/5002.htm

old page new page


#3

Thanks for the RedirectPermanent suggestion; no luck.

As for order –

Redirect 301 /Amy&William.JPG http://www.iayork.com/Images/Old_Images/Amy&William.JPG

The first “/Amy&William.JPG” is the non-existent file (or placekeeper file; I’ve tried both) that should be redirected to the second “http://www.iayork.com/Images/Old_Images/Amy&William.JPG” file – that’s the right order, isn’t it? (In any case, I tried the other way around too, no effect.)


#4

Yes, I think the order is right.

Are you using both at once?

[quote]Redirect 301 / http://www.panix.com/~iayork/

and

Redirect 301 /Amy&William.JPG http://www.iayork.com/Images/Old_Images/Amy&William.JPG[/quote]
BTW, I recently read Avoid Boring (Other) People and My Life Decoded. Interesting.


#5

I’m not using both at once – I just tried the one (Redirect 301 / http://www.panix.com/~iayork/) to make sure that my .htaccess file was getting read and interpreted; since that one did work, the file is at least approximately right. It’s just files that I can’t get to redirect.


#6

I tested files like you want to do. It works for me, with or without old file “placeholder”.

I suspect a typo in your .htaccess since you have case-sensitive names, or a conflict with other lines in your .htaccess.


#7

I have no other lines in my .htaccess, and I cut-and-pasted the names of the files.

Could you copy and paste the line that works for you, if you don’t mind?

Thanks.


#8

Redirect 301 /junk&Stuff.jpg http://www.mydomain.com/path/to/other/image.jpg

A request for http://www.mydomain.com/junk&Stuff.jpg goes to http://www.mydomain.com/path/to/other/image.jpg

(not the real domain name, obviously)

Are you sure you’re putting the .htaccess in the right place (in the domain home) with rw-r–r-- permission?

BTW, a server misconfiguration (fubar) is not out of the question.


#9

Are you sure you’re putting the .htaccess in the right place (in the domain home) with rw-r–r-- permission?

Since the .htaccess redirect does work for the directory, I think permissions etc. must be right.

BTW, a server misconfiguration (fubar) is not out of the question.

That was my first thought, but unfortunately I can’t get this to work on an unrelated site either, so there must be something wrong with my syntax. Damned if I can figure it out, though.


#10

My first guess is that the ampersand in the file name is the problem (and a bad idea). I suggest you either replace the ampersand in your filename, or substitute it in the redirect as an & and see what happens.

-Scott


#11

Sorry, I don’t follow that completely, Scott. Anyway, I agree avoiding & (= ampersand?) is better in general, but it did work for me.

You have a wordpress blog on that domain. Does it have a .htaccess file in a different directory that could be conflicting?

Another thought is a “weird” extra character in the .htaccess file from the way you put it on the server, but you said it works in one case, so that seems unlikely.


#12

The ampersand is a bad idea (I put that file up many years ago without thinking and am now stuck with it), but is not the problem here. I should have mentioned that I’ve tried the same thing with other files with no odd characters, without success. For example
Redirect 301 /Apple.JPG http://www.iayork.com/Images/Old_Images/Apple.JPG
is ignored also. I also tried escaping the ampersand with no effect.

You have a wordpress blog on that domain. Does it have a .htaccess file in a different directory that could be conflicting?

There are other .htaccess files, but none “upstream” of the Images folder – but I had thought that they should not interfere, anyway.

Another thought is a “weird” extra character in the .htaccess file from the way you put it on the server, but you said it works in one case, so that seems unlikely.

Right; again, I can redirect the directory as a whole, but not individual files.


#13

This recent thread involved conflict between “upstream” htaccess and “downstream” wordpress htaccess. Although not exactly the same, the pointers may help.


#14

Have you checked your log files to see if there’s any hint? When you got that 404, the log file should at least tell you what it was looking for. Then again, that info should have already shown up in your browser’s URL field.

Anyhow, give both the access.log and error.log a look for hints. They’re in your home directory under logs/YOURDOMAIN.com/http/

-Scott


#15

redirect 301 /Images/Apple.JPG http://www.iayork.com/Images/Old_Images/Apple.JPG

works. It doesn’t entirely make sense to me, because the .htaccess file is in /Images (so I thought it would consider the path to itself). But in fact I’m pretty sure this /Images/Apple.JPG is one of the first things I tried anyway … most likely I made a typo in that attempt and never went back to try again. Or something like that.

Anyway, it seems to be working now, and I’m not going to breathe too heavily on it lest it fall apart again.

Thanks for the suggestions and tips. (Looking back at my original question, I see I failed to give the essential information that these were in a particular subdirectory. Sorry about that.)

Ian