Welcome to HostingForumz.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

redirecting if missing file or page

 
   Web Hosting Problem Solving Community! (Home) -> Apache RSS
Next:  Audio Clips on The Economist site - How does they..  
Author Message
Troy Piggins

External


Since: Feb 18, 2008
Posts: 3



(Msg. 1) Posted: Mon Feb 18, 2008 7:04 am
Post subject: redirecting if missing file or page
Archived from groups: alt>apache>configuration (more info?)

At present my apache2 server gives a 404 message if someone tries
to access a non-existent page or file.

On some forums I have posted some links to photos in the past.
If I want to restructure my server so that those links are no
longer correct, is there a way in apache to attempt to redirect
them to the correct page? Or perhaps if someone clicks an old
link with a certain path in it, they can get a special 404
message? What do you recommend?

--
Troy Piggins | http://piggo.com/~troy _ __ (_) __ _ __ _ ___
| '_ \| |/ _` |/ _` |/ _ \
| .__/|_|\__, |\__, |\___/
|_| |___/ |___/

 >> Stay informed about: redirecting if missing file or page 
Back to top
Login to vote
patpro ~ Patrick Proniews

External


Since: May 30, 2005
Posts: 31



(Msg. 2) Posted: Mon Feb 18, 2008 7:04 am
Post subject: Re: redirecting if missing file or page [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

In article ,
Troy Piggins wrote:

> At present my apache2 server gives a 404 message if someone tries
> to access a non-existent page or file.
>
> On some forums I have posted some links to photos in the past.
> If I want to restructure my server so that those links are no
> longer correct, is there a way in apache to attempt to redirect
> them to the correct page? Or perhaps if someone clicks an old
> link with a certain path in it, they can get a special 404
> message? What do you recommend?


it depends on your restructuration.
If you have moved /your/page.html to /your/old/page.html it's quite easy
to setup a .htaccess file (or <Directory ...> in httpd.conf) so that
error document will be a specially crafted php file that can create a
redirect proposal for the user.
(I don't think an automatic redirect triggered by an error is a good
thing).

I'm using this kind of trick on my server. After moving a bunch of
directories from /some-directory/ to /some-directory/my-new-dir/, I've
created a 404 error page in php, looking like this:

.../..
<body>
<p>Hello,<br />
The page you're looking for has probably moved</p>
<p>You can try to reach it at this address: <?php echo '<a
href="'.dirname($_SERVER[REQUEST_URI]).'/my-new-dir/'.ba
sename($_SERVER[REQUEST_URI]).'">'.dirname($_SERVER[REQUEST_URI]).'/my-ne
w-dir/'.basename($_SERVER[REQUEST_URI]).'</a>'
; ?></p>
</body>
.../..

and my virtualhost config contains:

<Directory /usr/local/www/host/some-directory>
ErrorDocument 404 /some-directory/404.php
../..
</Directory>


hope this helps,

patpro

--
A vendre ! http://www.patpro.net/blog/index.php/2008/01/12/133

 >> Stay informed about: redirecting if missing file or page 
Back to top
Login to vote
Troy Piggins

External


Since: Feb 18, 2008
Posts: 3



(Msg. 3) Posted: Mon Feb 18, 2008 7:04 am
Post subject: Re: redirecting if missing file or page [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

* patpro ~ Patrick Proniewski is quoted & my replies are inline
* below :
> In article ,
> Troy Piggins wrote:
>
>> At present my apache2 server gives a 404 message if someone tries
>> to access a non-existent page or file.
>>
>> On some forums I have posted some links to photos in the past.
>> If I want to restructure my server so that those links are no
>> longer correct, is there a way in apache to attempt to redirect
>> them to the correct page? Or perhaps if someone clicks an old
>> link with a certain path in it, they can get a special 404
>> message? What do you recommend?
>
> it depends on your restructuration.
> If you have moved /your/page.html to /your/old/page.html it's quite easy
> to setup a .htaccess file (or <Directory ...> in httpd.conf) so that
> error document will be a specially crafted php file that can create a
> redirect proposal for the user.
> (I don't think an automatic redirect triggered by an error is a good
> thing).
>
> I'm using this kind of trick on my server. After moving a bunch of
> directories from /some-directory/ to /some-directory/my-new-dir/, I've
> created a 404 error page in php, looking like this:
>
> ../..
> <body>
> <p>Hello,<br />
> The page you're looking for has probably moved</p>
> <p>You can try to reach it at this address: <?php echo '<a
> href="'.dirname($_SERVER[REQUEST_URI]).'/my-new-dir/'.ba
> sename($_SERVER[REQUEST_URI]).'">'.dirname($_SERVER[REQUEST_URI]).'/my-ne
> w-dir/'.basename($_SERVER[REQUEST_URI]).'</a>'
> ; ?></p>
> </body>
> ../..
>
> and my virtualhost config contains:
>
> <Directory /usr/local/www/host/some-directory>
> ErrorDocument 404 /some-directory/404.php
> ../..
> </Directory>
>
>
> hope this helps,

Yes. That looks exactly like what I want. Thanks for that.
I'll have a look in more detail later. Thanks again.

--
Troy Piggins | http://piggo.com/~troy _ __ (_) __ _ __ _ ___
| '_ \| |/ _` |/ _` |/ _ \
| .__/|_|\__, |\__, |\___/
|_| |___/ |___/
 >> Stay informed about: redirecting if missing file or page 
Back to top
Login to vote
D. Stussy

External


Since: Nov 01, 2007
Posts: 25



(Msg. 4) Posted: Wed Feb 20, 2008 4:10 pm
Post subject: Re: redirecting if missing file or page [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

"Troy Piggins" wrote in message

> At present my apache2 server gives a 404 message if someone tries
> to access a non-existent page or file.
>
> On some forums I have posted some links to photos in the past.
> If I want to restructure my server so that those links are no
> longer correct, is there a way in apache to attempt to redirect
> them to the correct page? Or perhaps if someone clicks an old
> link with a certain path in it, they can get a special 404
> message? What do you recommend?

Use the commands Redirect and RedirectMatch to 301 the users to the correct
page.
 >> Stay informed about: redirecting if missing file or page 
Back to top
Login to vote
Troy Piggins

External


Since: Feb 18, 2008
Posts: 3



(Msg. 5) Posted: Thu Feb 21, 2008 9:23 am
Post subject: Re: redirecting if missing file or page [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

* D. Stussy is quoted & my replies are inline below :
> "Troy Piggins" wrote in message
>
>> At present my apache2 server gives a 404 message if someone tries
>> to access a non-existent page or file.
>>
>> On some forums I have posted some links to photos in the past.
>> If I want to restructure my server so that those links are no
>> longer correct, is there a way in apache to attempt to redirect
>> them to the correct page? Or perhaps if someone clicks an old
>> link with a certain path in it, they can get a special 404
>> message? What do you recommend?
>
> Use the commands Redirect and RedirectMatch to 301 the users to the correct
> page.

Thanks mate. That RedirectMatch does the trick nicely using
PCREs.

I had subdirs under dir "photos" according to dates:

..../photos/2007_08_30
..../photos/2008_03_31

and so on. The photos dir has become quite huge, so decided to
put yearly dirs in there, then the date ones under that:

..../photos/2007/2007_08_30
..../photos/2008/2008_03_31

But some forums I've posted photos to will have links to the
older URLs.

This solves that:

<Directory "/home/troy/public_html">
RedirectMatch permanent /~troy/photos/(200[0-9]{1})_(.*) http://piggo.com/~troy/photos/$1/$1_$2
</Directory>

Thanks for that.

--
Troy Piggins | http://piggo.com/~troy _ __ (_) __ _ __ _ ___
| '_ \| |/ _` |/ _` |/ _ \
| .__/|_|\__, |\__, |\___/
|_| |___/ |___/
 >> Stay informed about: redirecting if missing file or page 
Back to top
Login to vote
Display posts from previous:   
   Web Hosting Problem Solving Community! (Home) -> Apache All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]