• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 458
  • Last Modified:

400 Bad Request

Hello everybody:

On my site, I recieve a 400 Bad Request error when I try to access a directory without putting a slash after it (but it works if I do put the slash after it). Could you please tell me how to fix this?

URGENT, 500 Points
0
jsev1995
Asked:
jsev1995
  • 7
  • 2
  • 2
  • +3
1 Solution
 
NNDthCommented:
Hello,

This error, 400 bad request, means that a request for a URL has been made but the server is not configured or capable of responding to it. So, they only thing you can do is to contact your hosting company and ask them to configure the server in order to make it work.

I' d reccoment to make a custom 400 Error page, in order to inform your visitors that they have to type the splash at the end of the URL.

You can make a cusom 400 Error page by doing this:

1)Open notepad and make a file that contain this:

ErrorDocument 400 /dir_of_the_custom_error_page

2)Replace the "/dir_of_the_custom_error_page" with the directory of your custom 400error page. e.g. /400error.html - (You have to create it first)
3) Save the file as .htaccess at your index directory [this is the same directory with your main page, the index.html(/.php/.htm/etc)]. NOTE: you have to save the file as .htaccess, DO NOT CHANGE IT! DO NOT TOUCH IT!
4)Upload it to your main directory and you are done!

I hope my answer is helpful.
0
 
jsev1995Author Commented:
I am aware of how to use ErrorDocument. That does not answer my question, I don't want to tell people they have to add a slash, as ease of use is #1 in my webapp. Could you write me a RewriteRule or something similar to redirect it to the address, but with a slash? I know a lot about .htaccess, but I don't know how to correctly write RewriteRules to redirect things.
0
 
LeonardCooperCommented:
Hello,

No client should perform any intelligence in determining what to do with a URL, whether to add a slash, add a file name etc (Yes yes, we all know IE tries to get clever and does things like domain names etc etc)

This is a function of the webserver.
You do not mention what webserver you are using?
(http://mysite.com/stuff)
Generally, without the slash, the webserver looks for a file by this name "stuff". If it does not find one, it should "add a slash" and look for a directory by this name, and the load the configure DEFAULT FILE. (index.html, index.htm, index.php, default.htm, default.asp etc.)

So, some things to check is the confgured default page to load. Ensure that you have this default page in the directory in question. If not, consider changing the server config to suit your requirements - but remember that this will now be the rule!

That said, some times things go arwy on apache for various reason. In this case you can make use of MOD_REWRITE. (apache 2.x generally behaves itself in my experience, but this is useable in 1.3 and 2.x)

Apache documentation:
http://httpd.apache.org/docs/1.3/misc/rewriteguide.html
specifically the section titled: Trailing Slash Problem

RewriteEngine  on
RewriteBase    /~quux/
RewriteRule    ^foo$  foo/  [R]

This is a powerful module and can do many interesting things, for example, we use it so that ANY file requesting in a drectory is "re-written" to call a single file - so if you called somefile.php it will actually load defaultfile.php
    RewriteEngine on
    RewriteRule ^/dl/(.*)$ /dl/getcont.php

On apache, this can be included in a .htaccess file (if allowed!).

But I digress. Let us know what server and version you are using and the default file. Good starting place to look.

Leonard
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
jsev1995Author Commented:
Oh sorry, I'm on apache. Hostgator hatchling, to be exact. I tried this but it didn't work:

RewriteEngine  on
RewriteBase    /jobtracker
RewriteRule    ^jobtracker$  /jobtracker/  [R]

Could you please fix it for me? Thanks.
0
 
rama_krishna580Commented:
Hi,

look at here...
http://plone.org/documentation/tutorial/plone-apache/virtualhost

1.If http://example.com/foo/bar does not exist, redirect to http://other.example.com/foo/bar. (Put this in an .htaccess file in your top-level web directory.)
# .htaccess in root of example.com
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ http://other.example.com/$1 [R]

2.Handle all requests for top-level .html files and files with no extensions (http://example.com/foo, http://example.com/foo.html) with a single PHP program /foo/show.php. Also, ignore trailing characters in set { : ; , . } so URLs like "http://example.com/foo." can be copied-n-pasted from plain text sentences by inattentive users.
# .htaccess in root of example.com
RewriteRule ^/?([^/]*\.html?|[^\./]*)[:;,\.]*$ /foo/show.php [L,NS]Examples:
http://tomclegg.net/rewriterule
http://tomclegg.net/rewriterule.html;

3.Redirect GET requests for http://example.com/foo/bar to http://example.com/bar (and /foo/bar.html to /bar.html). Handle POST requests with PHP program rather than attempting to redirect a POST (which is unlikely to work well).
# .htaccess in foo folder in example.com's document root
RewriteEngine On
RewriteCond %{REQUEST_METHOD} GET
RewriteRule ^/?([^/]*\.html?|[^\./]*)[:;,\.]*$ /$1 [R,L,NS]
RewriteCond %{REQUEST_METHOD} POST
RewriteRule ^/?([^/]*\.html?|[^\./]*)[:;,\.]*$ /foo/show.php [L,NS]Examples:
http://tomclegg.net/w/rewriterule
http://tomclegg.net/w/rewriterule.html;

R.K
0
 
jsev1995Author Commented:
I want to redirect

http://example.com/jobtracker 

to

http://example.com/jobtracker/

That's all. Could you just write a .htaccess for that? Thanks again.
0
 
rama_krishna580Commented:
Hi,

Many experts recommend to set up a 301 redirect (permanent redirect) from YourSite.com to www.YourSite.com...

RewriteEngine On
RewriteCond %{HTTP_HOST} ^YourSite\.com [nc]
RewriteRule (.*) http://www.YourSite.com/$1 [R=301,L]

Replace "YourSite.com" with your real domain name.

More info.
http://corz.org/serv/tricks/htaccess2.php
http://www.webconfs.com/how-to-redirect-a-webpage.php

R.K
0
 
jsev1995Author Commented:
read my question carefully

I tried that, but http://mysite.com/jobtracker is still giving a 400 bad request error. Here is what I want you to do:

Write a .htaccess file that redirects jobtracker to jobtracker/

Post it here

That is all I want you to do and I am not interested in anything else, at all. I do not want to know anything else about .htaccess or how to do other things. That is all I want. Nothing else. So please
0
 
AngryBinaryCommented:
You mean you don't want a meandering lesson on regular expressions and Apache? Fine...

RewriteEngine On
RewriteCond %{THE_REQUEST} jobtracker$ [NC]
RewriteRule .* http://mysite.com/jobtracker/

My host already handles the 'missing slash' case, so I'm not able to verify that this rule doesn't fail. It looks right to me though... anyone able to see a problem with it?

--Randall
0
 
jsev1995Author Commented:
mine does too, which puzzles me. It only happens on this directory. I am using cakePHP inside this directory, if that helps anybody.

Thanks, you did exactly what I wanted, but it didn't work. Anyhow, .htaccess file from cakePHP:

<IfModule mod_rewrite.c>
   RewriteEngine on
   RewriteRule    ^$ app/webroot/    [L]
   RewriteRule    (.*) app/webroot/$1 [L]
</IfModule>

this is most likley causing the problem, please help. Thanks.
0
 
AngryBinaryCommented:
That particular mod_rewrite directive will short-circuit anything that comes after it. The [L] tells apache to stop rewriting if it finds a match. So, you'll need to stick your custom directives before these lines. What this next deal essentially does is look for 'jobtracker' and the end of the request ($), and replaces only that portion of the request with jobtracker/.

<IfModule mod_rewrite.c>
   RewriteEngine on
   RewriteRule    /jobtracker$ /jobtracker/ [NC]
   RewriteRule    ^$ app/webroot/    [L]
   RewriteRule    (.*) app/webroot/$1 [L]
</IfModule>

Again, I apologize if this doesn't work out exactly as planned, as I have no way to verify it on my own host.

--Randall
0
 
jsev1995Author Commented:
I am sorry but none of your solutions worked, so here is what I'll do:

I am going to give out a separate URL which redirects to jobtracker/

I have notified community support and requested that this question be deleted.

AngryBinary,

I thank you for your efforts, you are the only one who gave my what I wanted, but it didn't work.
0
 
jsev1995Author Commented:
community support notified.
0
 
DarthModCommented:
PAQd, 500 points refunded.

DarthMod
CS Moderator
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 7
  • 2
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now