Using 404 error pages correctly

Kudos to TB for the leading / AND for pointing out that Tigers’ code needs this in every Redirect line.

HOWEVER, I rely on mod_rewrite so much that I would prefer to use my code in post # 13. That said, though, mod_alias is much quicker (because it doesn’t need the regex engine) so I recommend:

  1. Correct the current code (add leading /'s to the filenames and delete all the “http://www.petalsandpatches.com” from the redirections) then
  2. Run a timing test using only the long list of Redirect statements
  3. Then save that .htaccess file offline.
  4. Create a new .htaccess file with just the mod_rewrite code from post #13
  5. Run another timing test.
  6. Compare the two timing test results and use ONLY the code which provides the fastest time.

I suspect that even this lengthy list of Redirect statements will be faster (after being corrected with the leading /'s and eliminating the superfluous “http://www.petalsandpatches.com” from the redirections) but making a test will provide proof either way.

Regards,

DK

I have altered my .htaccess file as was suggested viz, removed "http://www.petalsandpatches.com"and have the leading /.
The results were not what I expected.


The code I loaded was

# Added Error Pages
ErrorDocument 403 /error-pages/403error.htm
# ErrorDocument 404 http://www.petalsandpatches.com/error-pages/404error.php
ErrorDocument 404 /error-pages/404error.php

AddHandler server-parsed .html
AddHandler server-parsed .htm

# Added redirections from .htm to .php pages
Redirect 301 /stitcheries.htm /stitcheries.php
Redirect 301 /pincushions.htm /pincushions.php
Redirect 301 /ordering.htm /ordering.php
Redirect 301 /quilts.htm /quilts.php
Redirect 301 /applique.htm /applique.htm
Redirect 301 /chalkboards.htm /chalkboards.php
Redirect 301 /accessories.htm /accessories.php
Redirect 301 /seasidemoments.htm /seasidemoments.php
Redirect 301 /links.htm /links.php
Redirect 301 /bags.htm /bags.php
Redirect 301 /bears.htm /bears.php
Redirect 301 /stockists.htm /stockists.php
Redirect 301 /clothdolls.htm /clothdolls.php
Redirect 301 /index.htm /index.php
Redirect 301 /blockofthemonth /blockofthemonth.php
Redirect 301 /onfreedomswings./onfreedomswings.php
Redirect 301 /naturesgifts.htm /naturesgifts.php
Redirect 301 /orderform.htm /orderform.pdf
Redirect 301 /bears_viewcart.htm /bears.php

Could someone point out the blunder I have committed? I don’t know whether the emboldened 1st ErrorDocument is important. It is plain text in my code.

tigers,

That all looks fine EXCEPT the image does not display and blockofthemonth is missing (?) its .htm file extension - your ErrorDocument statements are correct (assuming you have the correct path {from your DocumentRoot} and filenames)… The only thing I can think of (without seeing your test URI) is that your host must NOT allow using your .htaccess file (difficult to imagine but I remember seeing something about GoDaddy (?) years ago not enabling .htaccess files from clients.

If that isn’t working (and your URI is EXACTLY one of the listed .htm files, then give the mod_rewrite a try (post #13 if I remember correctly).

Regards,

DK

Is that error document really .htm when the rest of the site is .php?

Both of those lines are missing extensions, and no idea what that second line running together might do.

Verify that the 403 should be .htm and not .php for us.

Fix/check those things, test a url that is exactly one of those (or several of those) listed pages - including the “orderform.htm” or “index.htm” or whichever - and then we can go from there.

2 Likes

jj,

Good eyes!

If there is no space between the . and the /, then there is a syntax error which should disable the entire website (I suspect). Typos? If not, then that is the problem.

As I said, though, I tend to rely on mod_rewrite and would use that to avoid all the superfluous typing (and typos).

Regards,

DK

Et al
I have made the changes all have suggest viz. fixed 403error.htm plus the missing extension the 2 pages.

Still didn’t work then found a space needed in

Redirect 301 /onfreedomswings.htm/onfreedomswings.php

Now it is ok. If I put a .htm it redirects immediately to .php without the intermediate 404 page.
An unknown page gives the 404 error page as required.

I was rather chuffed until a kind person pointed out that my contactus page failed the test. :frowning:

I have fixed that so at present all is well. I have some friends doing some testing for me.
I will let you know the test results.

1 Like

Tigers,

jeffreylees pointed out the TWO missing spaces two posts above (#25) and I echoed his finding in the post immediately above (#26).

Edit: Missing .htm and missing space in JL’s post.

Regards,

DK

If it is any help, this is the line I use in htaccess to redirect all html pages on the site to php:-

RedirectMatch 301 (.*)\.html$ http://www.example.com$1.php
1 Like

Sam,

That, too, would work.

However, RedirectMatch would require the regex engine (as would mod_rewrite) and, for Tigers short list (19 redirections), it’s probably faster to use Redirect at he has done. I do not know the time it takes to start the regex engine but suspect it may be in the realm of 20 - 100 Redirect statements but I’ll leave it to someone else to perform the time comparison exercise.

That said, I would rely on mod_rewrite as I ALWAYS have it running (for other reasons) and know how well mod_rewrite handles simple redirections like this.

Note: It was discovered that Tigers’ problem was with the syntax of just a few of his Redirect statements (they were difficult to see - kudos to TechnoBear and jeffreylees)

Regards,

DK

Thank you all very much for your help. My last look at stats showed that 404 errors went from > 100 to <10. Those people have found my wife’s current site and she is very happy.
The suggestions were most helpful. I aim to replace with Joomla and probably host the site myself and the mod_rewrite suggestions will come in most handy.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.