Forum Moderators: phranque

Message Too Old, No Replies

301 redirect, some work and some don't!

         

Pricey

11:08 am on May 21, 2004 (gmt 0)

10+ Year Member



Hi,
I've recently started playing around with htaccess, as I decided to make a custom 404 page and at the same time I wanted to rename some of my pages (from blue.shtml to blue_widget.shtml)

I started with about 5 pages with 301's (renamed pages like pinkelephant.shtml to pink_elephant.shtml) and the 404. I then changed some more pages and added them as 301's. These are NOT working, if I try the old page name in the url, it just brings up the 404 page. All 5 of the old 301's still work fine though. The code is exactly the same for every redirect I really can't understand it. When I header check the new 301's, they are returned as 302 Found, and bring up the 404 page. Here is the code:

redirect 301 blue.shtml [blahblah.co.uk...]

ErrorDocument 404 [blahblah.co.uk...]

I have also removed my .htaccess file completley from my server, but the server header check still tells me that my origional redirects are still working and the newer ones are still going to the 404 page.
How can this be when I have removed the htaccess file?!

Could it be that because the first 5 I tried to redirect automatically picked up the new pages names because the only difference in the page name was an underscore?

robotsdobetter

11:21 am on May 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Are you sure you removed all of it?

Could it be that because the first 5 I tried to redirect automatically picked up the new pages names because the only difference in the page name was an underscore?

No, I don't see how it could do that.

Pricey

11:30 am on May 21, 2004 (gmt 0)

10+ Year Member



Yeah, I removed the htaccess file completely. I have full fpt rights. Its odd.

I really need to list my full htaccess file to explain it better. The first 5 files I renamed and put a redirect on, changed from being

lightboxes.shtml to light_boxes.shtml (these work and the server header checker shows them as a 301)

and the newer redirects was changed from being

katana.shtml to katana_light_box.shtml (these don't work and the header checker shows it as a 302 Found, and sends back the 404 page)

- would the length of the newer files names have anything to do with it?

Also, this IS an apache server I'm on before anyone asks :P

robotsdobetter

11:41 am on May 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The length and underscores should have nothing to do with it at all. Have you tried to change the URLs at all to see if that works?

Pricey

11:45 am on May 21, 2004 (gmt 0)

10+ Year Member



Yes, I'v tried the url and the header checker. Same result every time :/

incywincy

11:51 am on May 21, 2004 (gmt 0)

10+ Year Member



why not show us anonymised .htaccess examples?
have you made any changes to your apache config file?

Pricey

11:58 am on May 21, 2004 (gmt 0)

10+ Year Member



No I've not changed the apache cfg file.

I'v put the text file of my htaccess on my server, if you go to my profile, get my homepage and put /htaccess.txt on the end, you can view it.

incywincy

1:04 pm on May 21, 2004 (gmt 0)

10+ Year Member



disclaimer: i'm not an expert on mod rewrite and i don't have my reference material to hand so the following would need to be tried out and corrected as necessary. but why not try using rewrite such as

RewriteRule (.*)display(.*)\.shtml /$1_display$2\.shtml [R=301]
RewriteRule (.*)stand(.*)\.shtml /$1_stand$2\.shtml [R=301]

this should handle singular and plural names.

jdMorgan

2:04 pm on May 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Pricey,

Make sure you flush your browser cache (Temporary Internet Files) after each and every change to any code that does URL rewriting or redirects. Otherwise, your browser will very often get a cached page from your local machine, ISP, or network cache, and it will contain the headers it was originally delivered with.

Jim

Pricey

2:13 pm on May 21, 2004 (gmt 0)

10+ Year Member



Hi Jim,

Yes, thats what I have been doing every time I make a change on it. At the moment I'm trying to get incy's rewrite code to work, but not having much luck.

Also, I changed my 404error to the correct format - thanks for that.

incywincy

2:25 pm on May 21, 2004 (gmt 0)

10+ Year Member



pricey, i'm sorry it's not working. it was just the principle i was trying to explain.

try a simple rewrite first

RewriteRule retaildisplay.shtml /retail_display.shtml [R=301]

then build in wild cards after you get this working

there are some apache gurus here who could probably achieve what you want with a few lines and get it right first time. inexperienced guys like me need to experiment!

jdMorgan

2:31 pm on May 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you want to rule out a caching issue, stick a fake query string on the end of your URLs when you request them. This will force your cache, your ISP cache, and any other network caches to pass the request through to your server.

First test, request http://yourdomain.com/testpage.shtml?test1
Second test, request http://yourdomain.com/testpage.shtml?test2
etc.

The fake query string usually won't interfere with serving the page, but it will force the request to be passed through all caches to your server.

I should also note that if you update your pages frequently, you should take control of caching issues, and set up your server to provide correct Expires, max-age, and Last-Modified headers.

Jim

Pricey

2:31 pm on May 21, 2004 (gmt 0)

10+ Year Member



Thanks incy, yeah I'm trying the basic stuff at the moment, I'll let you know how I get on!

although I still don't know why some of my redirects already work with

redirect 301 blue.shtml [mydomain.com...]

Pricey

9:26 am on May 24, 2004 (gmt 0)

10+ Year Member



Hurrah! I finally cracked it, thanks for all your help. This code actually works - please take note if you are a oneandone user and can't get 301's and 404's to work!


RewriteEngine On
Options +FollowSymlinks
RewriteBase /
RewriteCond %{HTTP_HOST} ^mydomain\.co.uk
RewriteRule ^(.*)$ http://www.mydomain.co.uk/$1 [R=permanent]
RewriteCond %{REQUEST_FILENAME}!-f
RewriteRule ^blue\.shtml$ http://www.mydomain.co.uk/blue_tiny_widgets.shtml$1 [R=permanent]
RewriteRule ^green\.shtml$ http://www.mydomain.co.uk/green_tiny_widgets.shtml$1 [R=permanent]
RewriteRule ^tinywidgets\.shtml$ http://www.mydomain.co.uk/tiny_widgets.shtml$1 [R=permanent]
ErrorDocument 404 /404error.shtml

gergoe

9:41 am on May 24, 2004 (gmt 0)

10+ Year Member



Why the
RewriteCond %{REQUEST_FILENAME} !-f
is for? It is only checks for the missing file *only* for the first RewriteRule, the others following the first one will not be conditional.

Pricey

11:55 am on May 24, 2004 (gmt 0)

10+ Year Member



Well it works if its there or if it isnt, so I'm happy either way :)