404 redirect to a custom missing page

Jul 14, 2008 at 7:33 PM
Hi,
is there any example to redirect 404 error code to generic error page? Please help.
Thank in advance!

Coordinator
Jul 15, 2008 at 3:43 PM
Edited Jul 15, 2008 at 3:43 PM
how about

  RewriteRule  ^.*$ /MyCustom404Page.htm  [L]
Jul 15, 2008 at 9:40 PM
Cheeso! 
RewriteRule  ^.*$ /MyCustom404Page.htm  [R:404 ]

would this be correct if bad link or page doesn't existed will get redirect to MyCustom404Page.htm?



Cheeso wrote:
how about

  RewriteRule  ^.*$ /MyCustom404Page.htm  [L]



Coordinator
Jul 16, 2008 at 4:18 PM

Davie!

ah, I don't know exactly what you are asking.  You don't want an R:404.  IIRF supports a 404 return code, but in that case, the option is [NF] (for Not Found), and the URL does not get rewritten.  In this case it is up to your web or app server to insert its own custom 404 page.  IIS has a 404 page handler, as does JSP, ASP.NET, and so on.

Also, the rule you suggested, assuming you eliminate the [R:404] thing, rewrites ALL requests to the MyCustom404Page.htm.  I don't think that is what you want. 

 

Jul 16, 2008 at 8:28 PM
Edited Jul 16, 2008 at 8:33 PM

Cheeso,

Thank for your replied, my website have serveral pages was indexed with google and they are on top of search results, but we are recently turn those page into database driven content, I like to delete those old static page out of root directory, and somehow if i can use IIRF just take a user to custom 404 page, and we are in shared web enviroments so we don't have a luxury of configured IIS options, I am lucky enough to ask my hosting comapny install IIRF just for me to be able to rewrite URL.

So my task is somehow i could rewrite or redirect any requested URL to missing pages (of course IIS will generate code 404 and display bllank page) and redirect them to a nice generic page says "We are recently revamp our site ... e.t.c".

If you could guide me for something like this : if this http://www.somewhere.com/*.cfm.. (missing page)  to http://www.somewhere.com/404.html

Millions thanks.

Davie


Cheeso wrote:

Davie!

ah, I don't know exactly what you are asking.  You don't want an R:404.  IIRF supports a 404 return code, but in that case, the option is [NF] (for Not Found), and the URL does not get rewritten.  In this case it is up to your web or app server to insert its own custom 404 page.  IIS has a 404 page handler, as does JSP, ASP.NET, and so on.

Also, the rule you suggested, assuming you eliminate the [R:404] thing, rewrites ALL requests to the MyCustom404Page.htm.  I don't think that is what you want. 

 




Coordinator
Jul 16, 2008 at 11:08 PM

how about

  RewriteRule  ^.+\.cfm$ /MyCustom404Page.htm  [R]

That says, for any page ending in cfm, then redirect (not rewrite) to the give custom static html page.  A redirect implies the URL address bar in the browser window will get updated. That will redirect any URL request that ends in cfm (such as http://server/page.cfm) , but not requests with query strings, such as http://server/page.cfm?s=15.   If you have to handle query strings , then you need a different rule, maybe something like this:

RewriteRule  ^/([^\?]+\.cfm)((\?.*)|())$  /MyCustom404Page.htm    [U,R]

This one captures ANY page that ends in .cfm, with or without a query string, and redirects it. Again, this is a redirect so the browser address bar gets updated. In the above I also added the U flag to unmangle the incoming URL request for logging purposes.

you could make the custom 404 page a dynamic page, something with server-side logic, for example, to log the requested page which is no longer present, or maybe log the referer. In this case you might want to do something like this:

RewriteRule  ^/([^\?]+\.cfm)((\?.*)|())$  /MyCustom404Page.aspx?p=$1$2    [U,R]


Davie wrote:

Cheeso,

Thank for your replied, my website have serveral pages was indexed with google and they are on top of search results, but we are recently turn those page into database driven content, I like to delete those old static page out of root directory, and somehow if i can use IIRF just take a user to custom 404 page, and we are in shared web enviroments so we don't have a luxury of configured IIS options, I am lucky enough to ask my hosting comapny install IIRF just for me to be able to rewrite URL.

So my task is somehow i could rewrite or redirect any requested URL to missing pages (of course IIS will generate code 404 and display bllank page) and redirect them to a nice generic page says "We are recently revamp our site ... e.t.c".

If you could guide me for something like this : if this http://www.somewhere.com/*.cfm.. (missing page)  to http://www.somewhere.com/404.html

Millions thanks.

Davie


Cheeso wrote:

Davie!

ah, I don't know exactly what you are asking.  You don't want an R:404.  IIRF supports a 404 return code, but in that case, the option is [NF] (for Not Found), and the URL does not get rewritten.  In this case it is up to your web or app server to insert its own custom 404 page.  IIS has a 404 page handler, as does JSP, ASP.NET, and so on.

Also, the rule you suggested, assuming you eliminate the [R:404] thing, rewrites ALL requests to the MyCustom404Page.htm.  I don't think that is what you want. 

 







Jul 17, 2008 at 1:53 PM
Cheeso,

Your replied is crystal clear, thanks in millions I will give it a try.

Davie


Cheeso wrote:

how about

  RewriteRule  ^.+\.cfm$ /MyCustom404Page.htm  [R]

That says, for any page ending in cfm, then redirect (not rewrite) to the give custom static html page.  A redirect implies the URL address bar in the browser window will get updated. That will redirect any URL request that ends in cfm (such as http://server/page.cfm) , but not requests with query strings, such as http://server/page.cfm?s=15.   If you have to handle query strings , then you need a different rule, maybe something like this:

RewriteRule  ^/([^\?]+\.cfm)((\?.*)|())$  /MyCustom404Page.htm    [U,R]

This one captures ANY page that ends in .cfm, with or without a query string, and redirects it. Again, this is a redirect so the browser address bar gets updated. In the above I also added the U flag to unmangle the incoming URL request for logging purposes.

you could make the custom 404 page a dynamic page, something with server-side logic, for example, to log the requested page which is no longer present, or maybe log the referer. In this case you might want to do something like this:

RewriteRule  ^/([^\?]+\.cfm)((\?.*)|())$  /MyCustom404Page.aspx?p=$1$2    [U,R]


Davie wrote:

Cheeso,

Thank for your replied, my website have serveral pages was indexed with google and they are on top of search results, but we are recently turn those page into database driven content, I like to delete those old static page out of root directory, and somehow if i can use IIRF just take a user to custom 404 page, and we are in shared web enviroments so we don't have a luxury of configured IIS options, I am lucky enough to ask my hosting comapny install IIRF just for me to be able to rewrite URL.

So my task is somehow i could rewrite or redirect any requested URL to missing pages (of course IIS will generate code 404 and display bllank page) and redirect them to a nice generic page says "We are recently revamp our site ... e.t.c".

If you could guide me for something like this : if this http://www.somewhere.com/*.cfm.. (missing page)  to http://www.somewhere.com/404.html

Millions thanks.

Davie


Cheeso wrote:

Davie!

ah, I don't know exactly what you are asking.  You don't want an R:404.  IIRF supports a 404 return code, but in that case, the option is [NF] (for Not Found), and the URL does not get rewritten.  In this case it is up to your web or app server to insert its own custom 404 page.  IIS has a 404 page handler, as does JSP, ASP.NET, and so on.

Also, the rule you suggested, assuming you eliminate the [R:404] thing, rewrites ALL requests to the MyCustom404Page.htm.  I don't think that is what you want.