Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to redirect page if invalid url entry

Status
Not open for further replies.

dreampolice

Technical User
Dec 20, 2006
85
0
0
US
I have a url where the last character or characters has to be a number. Everything works great where the last character/s is always a number after the final / in the URL:
or
or

Sometimes a user will manually put the url in and enter a non Integer at the end of the url where it should only be a Integer:

This gives me an error message and I was hoping to create something in JavaScript to give a customized error page or redirect to a customized error page. The main thing is I dont want the Server side error message to show when someone puts in an invalid URL entry with non integer number after the last / in the urls.

Please advise how I can handle this using JavaScript?
 
As far as I know, you would have to do this server-side. Whether this is by using your web hosts control panel to create a custom 404 page that detects for a correct URL and returns a 200 response, or whether this is with server-side scripting that sets a generic 404 page, I can't say... But I'm pretty sure you will not be able to do this client-side.

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
If you are using IIS, there is an option to redirect based on ANY error... 403, 404, etc... And they can all redirect to different pages!
Brett
 
Thanks,

I am using Apache Tomcat 4.1.27.

I googled URL rewrite and came up with this for input into my web.xml
Code:
 <filter>
           <filter-name>ErrorServletMessage</filter-name>
           <filter-class>mypackage.ErrorServletMessage</filter-class>
        </filter>
        <filter-mapping>
           <filter-name>ErrorServletMessage</filter-name>
           <url-pattern>/*</url-pattern>
        </filter-mapping>

It prevented me from looking at my page because it shows 404 status.

Please advise and sorry this is turning into Server side post.
 
Since you are on a Unix box, have you tried using .htaccess files in each directory? They worked for me when I was running on a Unix box. They can also password protect directories and other things. Do a google search on them and check them out! :)

Hope that helps!
Brett
 
Hi

Brett, the .htaccess file does not influence Tomcat. Maybe you had Tomcat behind httpd, so the .htaccess worked before the request reached Tomcat.

I also propose reposting this question. In forum877.

Feherke.
 
Thanks, I think in my version of Tomcat 4.1.27 (Apache Tomcat on Windows 2000 Server) I cant redirect 403, 404 etc errors. Anyways I finally did solve the issue by adding Server side Exception handling in the correct area of my Servlet.

Thanks again for all your input.
 
Thanks Feherke. I didn't realize that. I just know it worked for me and I didn't know if dreampolice could use that information or not.

Good idea dreampolice. I'm glad you got it figured out!

Brett
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top