Redirection for deleted pages

Redirection for deleted pages

am 26.06.2007 22:44:57 von Phil Steer

(I am fairly sure that the solution to this problem is an Apache
configuration issue, so please bear with me during the seemingly irrelevant
introduction.)

I have a personal (i.e. 'amateur') website with over 1000 HTML pages, which
I want to convert to dynamic page creation from a mySQL database.

I thought that I could use a custom 404 error page to assist with the
process: having deleted an existing HTML page any requests would go to the
404 error page, where PHP code would look up the requested page URL in the
database, retreive the data, create and return the page.

However, this simple idea does not work; mainly, it seems, because the
server attempts to return a 'closest match'. So, if I delete page01.htm then
the server will return page02.htm; or present a choice if there are multiple
closest matches.

I have tried setting 'Options -MultiViews' in .htaccess but this doesn't
work (perhaps because of the AllowOverride setting imposed by my hosting
provider?)

It also seems that requests for deleted pages do not always generate 404
errors: I also get various 3xx redirection errors.

I have tried setting ErrorDocument handlers for these in .htaccess, but
although redirection to the error page occurs, I don't seem to be able to
obtain the requested URL from the PHP server variables.

Given the above, please could someone suggest to me how I should achieve my
aim: of translating a request for a deleted HTML page into a dynamically
created page using the URL as the key into the database?

Should I use the URL rewriting engine, or is there some easier option.

Many thanks.

Best Regards, Phil Steer

Re: Redirection for deleted pages

am 27.06.2007 02:37:02 von shimmyshack

On Jun 26, 9:44 pm, "Phil Steer" wrote:
> (I am fairly sure that the solution to this problem is an Apache
> configuration issue, so please bear with me during the seemingly irrelevant
> introduction.)
>
> I have a personal (i.e. 'amateur') website with over 1000 HTML pages, which
> I want to convert to dynamic page creation from a mySQL database.
>
> I thought that I could use a custom 404 error page to assist with the
> process: having deleted an existing HTML page any requests would go to the
> 404 error page, where PHP code would look up the requested page URL in the
> database, retreive the data, create and return the page.
>
> However, this simple idea does not work; mainly, it seems, because the
> server attempts to return a 'closest match'. So, if I delete page01.htm then
> the server will return page02.htm; or present a choice if there are multiple
> closest matches.
>
> I have tried setting 'Options -MultiViews' in .htaccess but this doesn't
> work (perhaps because of the AllowOverride setting imposed by my hosting
> provider?)
>
> It also seems that requests for deleted pages do not always generate 404
> errors: I also get various 3xx redirection errors.
>
> I have tried setting ErrorDocument handlers for these in .htaccess, but
> although redirection to the error page occurs, I don't seem to be able to
> obtain the requested URL from the PHP server variables.
>
> Given the above, please could someone suggest to me how I should achieve my
> aim: of translating a request for a deleted HTML page into a dynamically
> created page using the URL as the key into the database?
>
> Should I use the URL rewriting engine, or is there some easier option.
>
> Many thanks.
>
> Best Regards, Phil Steer

The trouble is likely to be mod_speling, but that aside, you should
not be using the method you are attempting to use, (404) instead you
should serve 200 OK headers for every resource successfully sent to
the user, this way you can take advantage of things like caching, and
the normal browser (and SEO) reaction to standard headers - when
properly sent.
My advice would be to use rewrites as you suggest:


RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L,NS]


Then use $_SERVER['REQUEST_URI'] inside the php script, and use the
value to grab the DB content and serve the page. The only trouble with
this method is that 404s are never generated - completely the other
end of the stick!! But hey it's better to have 200 OK most of the
time, and serve a custom 404 page for the small minority of true not
founds, that to have all 404s!

I am sure you are doing this to always maintain static URLs, which is
the right idea - they should not need to change regardless of the
underlying filesystem/db process, the mapping is created using
rewrites and can be tweaked to accomodate any scheme you might employ.

Re: Redirection for deleted pages

am 27.06.2007 09:00:10 von Phil Steer

Many thanks for taking the time and trouble to write such a detailed and
helpful reply. I will attempt to implement your suggestions and let you know
how I get on. Many thanks again.

Best Regards, Phil

"shimmyshack" wrote in message
news:1182904622.392982.50560@n60g2000hse.googlegroups.com...

> The trouble is likely to be mod_speling, but that aside, you should
> not be using the method you are attempting to use, (404) instead you
> should serve 200 OK headers for every resource successfully sent to
> the user, this way you can take advantage of things like caching, and
> the normal browser (and SEO) reaction to standard headers - when
> properly sent.
> My advice would be to use rewrites as you suggest:
>
>
> RewriteEngine On
> RewriteBase /
> RewriteCond %{REQUEST_FILENAME} !-f
> RewriteCond %{REQUEST_FILENAME} !-d
> RewriteRule . /index.php [L,NS]
>

>
> Then use $_SERVER['REQUEST_URI'] inside the php script, and use the
> value to grab the DB content and serve the page. The only trouble with
> this method is that 404s are never generated - completely the other
> end of the stick!! But hey it's better to have 200 OK most of the
> time, and serve a custom 404 page for the small minority of true not
> founds, that to have all 404s!
>
> I am sure you are doing this to always maintain static URLs, which is
> the right idea - they should not need to change regardless of the
> underlying filesystem/db process, the mapping is created using
> rewrites and can be tweaked to accomodate any scheme you might employ.
>

Re: Redirection for deleted pages

am 27.06.2007 20:48:34 von Phil Steer

Perfect! Many thanks.Your help is much appreciated.

Best Regards, Phil

"shimmyshack" wrote in message >
The trouble is likely to be mod_speling, but that aside, you should
> not be using the method you are attempting to use, (404) instead you
> should serve 200 OK headers for every resource successfully sent to
> the user, this way you can take advantage of things like caching, and
> the normal browser (and SEO) reaction to standard headers - when
> properly sent.
> My advice would be to use rewrites as you suggest:
>
>
> RewriteEngine On
> RewriteBase /
> RewriteCond %{REQUEST_FILENAME} !-f
> RewriteCond %{REQUEST_FILENAME} !-d
> RewriteRule . /index.php [L,NS]
>

>
> Then use $_SERVER['REQUEST_URI'] inside the php script, and use the
> value to grab the DB content and serve the page. The only trouble with
> this method is that 404s are never generated - completely the other
> end of the stick!! But hey it's better to have 200 OK most of the
> time, and serve a custom 404 page for the small minority of true not
> founds, that to have all 404s!
>
> I am sure you are doing this to always maintain static URLs, which is
> the right idea - they should not need to change regardless of the
> underlying filesystem/db process, the mapping is created using
> rewrites and can be tweaked to accomodate any scheme you might employ.
>