views:

93

answers:

1

Hi,

I changed the way my URL are working on my server. It is now www.myserver.com/service instead of www.myserver.com/test/service

I have added a RedirectMatch 301 to my Apache conf file to redirect any access to www.myserver.com/test to www.myserver.com/.

I am receiving file to this server via an HTTP PUT at this URL for example : www.myserver.com/test/service/put/myfile.xml

The server sending the file don't handle the 301 HTTP status code so the files didn't arrived anymore.

Is there a way to rewrite the URL when it is a PUT Request in order to don't miss any file?

Thanks,

Benjamin


UPDATE :

Here is the RewriteLog content after applying this :

RewriteEngine on
RewriteCond %{REQUEST_METHOD} =PUT
RewriteRule ^/test/(.*) /$1 [PT]

log :

XX.XXX.XXX.XXX - - [16/May/2010:06:33:40 +0000] [www.myserver.com/sid#7f378508aa30][rid#7f378538a828/initial] (2) init rewrite engine with requested uri /test/service/put/myfile.xml
XX.XXX.XXX.XXX - - [16/May/2010:06:33:40 +0000] [www.myserver.com/sid#7f378508aa30][rid#7f378538a828/initial] (3) applying pattern '^/test/(.*)' to uri '/test/service/put/myfile.xml'
XX.XXX.XXX.XXX - - [16/May/2010:06:33:40 +0000] [www.myserver.com/sid#7f378508aa30][rid#7f378538a828/initial] (4) RewriteCond: input='PUT' pattern='=PUT' => matched
XX.XXX.XXX.XXX - - [16/May/2010:06:33:40 +0000] [www.myserver.com/sid#7f378508aa30][rid#7f378538a828/initial] (2) rewrite '/test/service/put/myfile.xml' -> '/service/put/myfile.xml'
XX.XXX.XXX.XXX - - [16/May/2010:06:33:40 +0000] [www.myserver.com/sid#7f378508aa30][rid#7f378538a828/initial] (2) forcing '/service/put/myfile.xml' to get passed through to next API URI-to-filename handler
XX.XXX.XXX.XXX - - [16/May/2010:06:33:40 +0000] [www.myserver.com/sid#7f378508aa30][rid#7f3785393858/subreq] (2) init rewrite engine with requested uri /service/put/myfile.xml
XX.XXX.XXX.XXX - - [16/May/2010:06:33:40 +0000] [www.myserver.com/sid#7f378508aa30][rid#7f3785393858/subreq] (3) applying pattern '^/test/(.*)' to uri '/service/put/myfile.xml'
XX.XXX.XXX.XXX - - [16/May/2010:06:33:40 +0000] [www.myserver.com/sid#7f378508aa30][rid#7f3785393858/subreq] (1) pass through /service/put/myfile.xml

UPDATE 2 :

Apache configuration :

RewriteEngine on
RewriteLog "/etc/httpd/logs/rewrite.log"
RewriteLogLevel 9
RewriteCond %{REQUEST_METHOD} =PUT
RewriteRule ^/test/(.*) /$1 [PT]
RedirectMatch 301 ^/test/(.*)$ http://www.myserver.com/$1
AliasMatch ^/style/(.*)?$ "/var/www/test/www/style/$1"
AliasMatch ^/js/(.*)?$ "/var/www/test/www/js/$1"
AliasMatch ^/min/(.*)?$ "/var/www/test/www/min/$1"
AliasMatch ^/downloads/(.*)?$ "/var/www/test/www/downloads/$1"
AliasMatch ^/images/(.*)?$ "/var/www/test/www/images/$1"
AliasMatch ^/chart/(.*)?$ "/var/www/test/www/graphs/$1"
AliasMatch ^(/.*)?$ "/var/www/test/www/index.php$1"

<Directory "/var/www/test">
    AllowOverride None
    Allow from all
</Directory>
+1  A: 

There is, with mod_rewrite:

RewriteEngine on
RewriteCond %{REQUEST_METHOD} =PUT
RewriteRule ^/test/(.*) /$1
Artefacto
mod_rewrite will not issue any 302 or 301 redirect?
benjisail
No, unless you tell it to (or you give a full URL).
Artefacto
With this mod_rewrite rule I am getting a 405 HTTP error status saying :"The requested method PUT is not allowed for the URL /test/service/put/myfile.xml"when I try to send a PUT request to my server instead of the 301 HTTP status.How can I verify that the rewrite is done correctly?After the RewriteRule I am doing AliasMatch. Will they still work if the rewrite happen?Thanks!
benjisail
Tru adding the PT (passthru) flag to the rewriterule: RewriteRule ^/test/(.*) /$1 [PT]
Artefacto
Thanks!!I am now getting a 404 error...Something is still not working...
benjisail
Here is the apache access_log : XX.XXX.XXX.XXX - user [16/May/2010:06:12:25 +0000] "PUT /test/service/put/myfile.xml HTTP/1.1" 404 1759 "-" "-"
benjisail
I have update my question with the result of the rewriteLog.
benjisail
The log looks file. Show your AliasMatch directive and increase the logging verbosity of apache itself. Better yet, substitute the AliasMatch directive for a rewrite rule.
Artefacto
I increased the logging verbosity of apache but nothing useful shows up when I try to PUT a file to my server.I have added my aliasMatch directives in my question.
benjisail
So you pass the requested URI to /var/www/test/www/index.php as path info? I don't know if that's supposed to work... Try aliasing the directory where index.php (say Alias /mydir/ "/var/www/test/www/") and then change the rewrite rule to RewriteRule ^/test/(.*) /mydir/index.php/$1 [PT]
Artefacto
This is not working...This is harder that I was thinking...
benjisail
How can I substitute the AliasMatch directive for a rewrite rule?What would be the purpose of this?Will this solve my problem?Thanks
benjisail