Jump to content


Photo

[apache] error 400 when rewriting urls


  • Please log in to reply
3 replies to this topic

#1 Bart

Bart

  • Network Admins
  • 8,524 posts
  • Location:The Netherlands
  • Division:Revora
  • Job:Network Leader

Posted 21 January 2008 - 08:29 PM

i'm having trouble with apache 2.2 and mod_rewrite. i have the following .htaccess file:

RewriteEngine On
#RewriteRule ^(.*)?\.html$ index.php?action=$1 [QSA,L]
RewriteRule ^(.*)?\.htm$ bla.html [L]
(the first line is what i eventually want, the second is what i currently use for testing)

when i request x.htm, the server returns error 400 (bad request). i can't explain why. in any case it's somewhere in the server, i am sure the rewrite rule is ok. the file bla.html exists and is accesible trough the normal url.
it works when i replace bla.html with it's absolute path (/bure/MDD/src/bla.html), but i don't want that

note that this .htaccess file is in an alias. it works fine from the documentroot

apache logs:

access.log
127.0.0.1 - - [21/Jan/2008:21:05:57 +0100] "GET /buro/MDD/src/x.htm HTTP/1.1" 400 226
127.0.0.1 - - [21/Jan/2008:21:05:57 +0100] "GET /favicon.ico HTTP/1.1" 404 209
127.0.0.1 - - [21/Jan/2008:21:05:57 +0100] "GET /favicon.ico HTTP/1.1" 404 209
127.0.0.1 - - [21/Jan/2008:21:05:57 +0100] "GET /favicon.ico HTTP/1.1" 404 209

error.log
Starting the Apache2.2 service
The Apache2.2 service is running.
rmine the server's fully qualified domain name, using 10.8.0.2 for ServerName
[Mon Jan 21 21:05:54 2008] [notice] Apache/2.2.8 (Win32) PHP/5.2.5 configured -- resuming normal operations
[Mon Jan 21 21:05:54 2008] [notice] Server built: Jan 18 2008 00:37:19
[Mon Jan 21 21:05:54 2008] [notice] Parent: Created child process 5932
httpd.exe: Could not reliably determine the server's fully qualified domain name, using 10.8.0.2 for ServerName
httpd.exe: Could not reliably determine the server's fully qualified domain name, using 10.8.0.2 for ServerName
[Mon Jan 21 21:05:57 2008] [notice] Child 5932: Child process is running
[Mon Jan 21 21:05:57 2008] [notice] Child 5932: Acquired the start mutex.
[Mon Jan 21 21:05:57 2008] [notice] Child 5932: Starting 64 worker threads.
[Mon Jan 21 21:05:57 2008] [notice] Child 5932: Starting thread to listen on port 80.
[Mon Jan 21 21:05:57 2008] [error] [client 127.0.0.1] Invalid URI in request GET /buro/MDD/src/x.htm HTTP/1.1
[Mon Jan 21 21:05:57 2008] [error] [client 127.0.0.1] File does not exist: C:/software/apache/htdocs/favicon.ico
[Mon Jan 21 21:05:57 2008] [error] [client 127.0.0.1] File does not exist: C:/software/apache/htdocs/favicon.ico
[Mon Jan 21 21:05:57 2008] [error] [client 127.0.0.1] File does not exist: C:/software/apache/htdocs/favicon.ico

rewrite.log
127.0.0.1 - - [21/Jan/2008:21:05:57 +0100] [localhost/sid#6f5148][rid#f83300/initial] (3) [perdir D:/School/Buro 302/Workspace/MDD/src/] strip per-dir prefix: D:/School/Buro 302/Workspace/MDD/src/x.htm -> x.htm
127.0.0.1 - - [21/Jan/2008:21:05:57 +0100] [localhost/sid#6f5148][rid#f83300/initial] (3) [perdir D:/School/Buro 302/Workspace/MDD/src/] applying pattern '^(.*)?\.htm$' to uri 'x.htm'
127.0.0.1 - - [21/Jan/2008:21:05:57 +0100] [localhost/sid#6f5148][rid#f83300/initial] (2) [perdir D:/School/Buro 302/Workspace/MDD/src/] rewrite 'x.htm' -> 'bla.html'
127.0.0.1 - - [21/Jan/2008:21:05:57 +0100] [localhost/sid#6f5148][rid#f83300/initial] (3) [perdir D:/School/Buro 302/Workspace/MDD/src/] add per-dir prefix: bla.html -> D:/School/Buro 302/Workspace/MDD/src/bla.html
127.0.0.1 - - [21/Jan/2008:21:05:57 +0100] [localhost/sid#6f5148][rid#f83300/initial] (1) [perdir D:/School/Buro 302/Workspace/MDD/src/] internal redirect with D:/School/Buro 302/Workspace/MDD/src/bla.html [INTERNAL REDIRECT]

help :p
bartvh | Join me, make your signature small!
Einstein: "We can’t solve problems by using the same kind of thinking we used when we created them."

#2 Clement

Clement

    title available

  • Network Staff
  • 1,442 posts
  • Location:France
  • Projects:Various
  •  T3A Team Chamber Member
  • Division:Revora
  • Job:Developer

Posted 22 January 2008 - 05:57 PM

RewriteRule ^(.*)?\.htm$ bla.html [L]

Shouldn't be:

RewriteRule ^(.*)?\.htm$ /bla.html [L]

?
Posted Image

#3 Phil

Phil

    Force Majeure

  • Network Leaders
  • 7,971 posts
  • Location:Switzerland
  • Projects:Revora, C&C:Online
  •  Thought Police
  • Division:Revora
  • Job:Network Leader
  • Donated
  • Association

Posted 22 January 2008 - 06:57 PM

Just tried out your rewrite and it works fine (Apache/2.2.4). Are you sure you have no further rewrites in place?

revorapresident.jpg
My Political Compass

Sieben Elefanten hatte Herr Dschin
Und da war dann noch der achte.
Sieben waren wild und der achte war zahm
Und der achte war's, der sie bewachte.


#4 Bart

Bart

  • Network Admins
  • 8,524 posts
  • Location:The Netherlands
  • Division:Revora
  • Job:Network Leader

Posted 23 January 2008 - 05:25 PM

As it turns out, the problem was that I was running the application in an alias (a suburl on server which points to a different directory in the filesystem). Therefore I needed to add a "RewriteBase /location/of/script". I tried putting it in the <Directory> specification in the server configuration, so it could stay away from the .htaccess and keep my app portable. Unfortunately that's not possible.

So now I put it in the .htaccess and promoted that file to something that should be edited for each installation of the site.

@TDP: No there shouldn't be a slash, because that would make it absolute. So you'd request http://server/mystuff/blablabla.htm, the redirect would be to http://server/bla.html
bartvh | Join me, make your signature small!
Einstein: "We can’t solve problems by using the same kind of thinking we used when we created them."




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users