Welcome to WebmasterWorld Guest from 3.226.251.205

Forum Moderators: Ocean10000 & phranque

Message Too Old, No Replies

ErrorDocument redirect

Question about ErrorDocument

     
12:26 pm on Apr 27, 2005 (gmt 0)

New User

10+ Year Member

joined:Apr 26, 2005
posts:4
votes: 0


I was wondering if it is possible to script the ErrorDocument at all or if it has any commands that you could use? A section of my site needs URLs that end in / but the search engines return the URL without the ending slash. Can I make the ErrorDocument 404 redirect to the existing URL with a slash? or can I pass the URL to a php script to examine if I should attempt to retry at a different address (check to see if the slash needs to be added)?
4:18 pm on Apr 27, 2005 (gmt 0)

Senior Member

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

joined:Mar 31, 2002
posts:25430
votes: 0


In a properly-configured server, mod_dir ahould append a slash to any directory request that is missing the trailing slash.

YOu could also use mod_rewrite to append the slashes where needed, *if* the case where you need to add a slash is easy to identify in a consistent manner.

You may use any kind of file or script as an ErrorDocument, but if the search engines are consistently listing your URLs without a slash, then it would be a very bad idea to use a 404 response to handle these requests -- Your pages would rightly be removed from the search index because your server would be saying they don't exist.

I recommend handling the 'fix-up' entirely within your server, without using a 404 response.

If you provide more details on the type of resource that these missing-slash URLs refer to, we may be able to give you more focused recommendations. Are they directories, pages, or scripts? Are they consistently named and consistently-identifiable? Do they all reside in some easily-identifiable subdirectory? Anything that can be used to classify them might be helpful.

Also, WHY does your site "need" that trailing slash? -- It might be far simpler and more efficient to fix that, rather than to implement a work-around.

Jim

10:59 am on Apr 28, 2005 (gmt 0)

New User

10+ Year Member

joined:Apr 26, 2005
posts:4
votes: 0


I am using the script FarODP to host a nicer version of DMOZ on my site with mod-rewrite feature for SEO friendly directory enabled. It is all run from an index.php. The mod_rewrite normally appends the path name to the php file in a variable I believe. Below is my existing mod rewrite for the directory located in the directory /dir/:

RewriteEngine On
RewriteRule ^(.+/)$ index.php?c=/$1 [L]

I added the following as a temporary fix so it displays the index page when it is messed up.

ErrorDocument 400 /dir/
ErrorDocument 404 /dir/

All I really want it to do is add the extra / when needed. the only other file it calls within the /dir/ folder is a CSS i could move elsewhere. so if anything was called within the path /dir/ I would want to make sure it ended with /. If you were able to find my direcotry or go the farfarfar website and look at there demo's you could go to a sub page and erase the ending slash and you would see the throw errors. Anyhow thanks for the help thus far. What is my best course of action?

1:49 pm on Apr 28, 2005 (gmt 0)

Senior Member

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

joined:Mar 31, 2002
posts:25430
votes: 0


Without an iron-clad definition of "add the slash when needed", this might do to append a slash "when needed":

RewriteEngine On
RewriteRule ^(.+)/?$ index.php?c=/$1/ [L]

It will definitely add the slash, the question is whether it is selective enough in your environment. It might add a slash to a URL that you don't want it to add a slash to, and pass that URL to the script when you don't expect that URL to be processed by the script. Everything depends on how specific the URL-match must be to work with your set-up. That's why it's good to have very specific and unambiguous URL-mapping definitions before starting.

Jim

12:30 pm on Apr 29, 2005 (gmt 0)

New User

10+ Year Member

joined:Apr 26, 2005
posts:4
votes: 0


That did not seem to work /dir/Arts shuold become /dir/Arts/ I would think but it still throws a not found error. Odd.. I think maybe apache see's that there isn't the File arts it doesnt work. Is there any way to do something like this:

ErrorDocument 404 ^(.+/)$ /dir/index.php?c=/$1/

or can I chage my rewrite so regardless of what gets called it will try to rewrite?