mod_rewrite not finding files that exists - apache

I am working on a project that uses Apache 2.2 and we are implementing a rewrite rule that uses the file on the local disk if it exists and if it doesn't then it using another server to server the file. To simplify the problem I have just put a rule in that redirects to a given URL if the file doesn't exist:
RewriteCond %{REQUEST_URI} !-f
RewriteRule ^(.*) /notfound.html
Now the output on that request from the rewrite log is as follows:
127.0.0.1 - - [30/May/2016:16:54:01 +1000] [www.blah.com/sid#7f8a4ee0f358][rid#7f8a4f45d7d8/initial] (2) init rewrite engine with requested uri /index.html
127.0.0.1 - - [30/May/2016:16:54:01 +1000] [www.blah.com/sid#7f8a4ee0f358][rid#7f8a4f45d7d8/initial] (3) applying pattern '^(.*)' to uri '/index.html'
127.0.0.1 - - [30/May/2016:16:54:01 +1000] [www.blah.com/sid#7f8a4ee0f358][rid#7f8a4f45d7d8/initial] (4) RewriteCond: input='/index.html' pattern='!-f' => matched
127.0.0.1 - - [30/May/2016:16:54:01 +1000] [www.blah.com/sid#7f8a4ee0f358][rid#7f8a4f45d7d8/initial] (2) rewrite '/index.html' -> '/notfound.html'
127.0.0.1 - - [30/May/2016:16:54:01 +1000] [www.blah.com/sid#7f8a4ee0f358][rid#7f8a4f45d7d8/initial] (2) local path result: /notfound.html
127.0.0.1 - - [30/May/2016:16:54:01 +1000] [www.blah.com/sid#7f8a4ee0f358][rid#7f8a4f45d7d8/initial] (2) prefixed with document_root to /var/www/html/notfound.html
127.0.0.1 - - [30/May/2016:16:54:01 +1000] [www.blah.com/sid#7f8a4ee0f358][rid#7f8a4f45d7d8/initial] (1) go-ahead with /var/www/html/notfound.html [OK]
When I turn off the rewrite rules and run the same command I get a 200 response from the server.
The server has permissions to view the file.
Any help would be appreciated.

Use %{REQUEST_FILENAME} instead of %{REQUEST_URI}, thus:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*) /notfound.html
%{REQUEST_URI} will contain only /index.html, so it won't work unless the filesystem has an index.html file in the root.
%{REQUEST_FILENAME} will contain the full path to the requested filename (including the Apache directory root for that domain)
Note that REQUEST_URI and REQUEST_FILENAME might happen to be equal under some specific circumstances, but more often than not, they won't. So if you are checking for a filename in the server's local filesystem (as it's the case), use the specific.

Related

htaccess canonical URL subdirectory

I have the same problem as htaccess - canonical URL when redirecting to subdirectory, but the solution there appears to use a hardcoded host name in the htaccess file which I can't do.
The following is in my htaccess file in the root directory which works fine for redirecting all requests into the /public directory with the exception of node_modules:
<IfModule mod_rewrite.c>
RewriteEngine on
# Allow node_modules
RewriteRule ^node_modules($|/) - [L]
# Rewrite everything to public
RewriteRule ^(.*)$ public/$1 [L,QSA]
</IfModule>
However I realize that the pages can be accessed through two different URLs, for example:
https://localhost/application1/foo/books.php
https://localhost/application1/public/foo/books.php
How do I either prevent the second one (ideally) or have it redirect to the first one?
I tried various RewriteCond statements with %{THE_REQUEST} but they turned out to be infinite loops. As mentioned above this needs to be hostname-agnostic as the application runs on different environments.
Update
I tried #SuperDuperApps answer below with the following in my .htaccess, which seemed to make no difference:
RewriteEngine on
RewriteCond $1 !^node_modules($|/)
RewriteCond $1 !^public($|/)
RewriteRule ^(.*)$ public/$1 [L,QSA]
RewriteRule ^public/ - [L,R=404]
After enabling RewriteLogLevel 3 in my dev server, this is what appears when I access a file with /public in the URL:
192.168.33.1 - - [27/Jan/2017:22:52:45 --0500] [localhost/sid#7f4a0d1d2cf0][rid#7f4a0d6a5d58/initial] (1) [perdir /var/www/html/application1/public/] pass through /var/www/html/application1/public/common/assets/js/nav.min.js
And this is when I access the same file without /public in the URL (desired behaviour):
192.168.33.1 - - [27/Jan/2017:22:48:45 --0500] [localhost/sid#7f4a0d1d2cf0][rid#7f4a0d684738/initial] (3) [perdir /var/www/html/application1/] add path info postfix: /var/www/html/application1/common -> /var/www/html/application1/common/assets/js/nav.min.js
192.168.33.1 - - [27/Jan/2017:22:48:45 --0500] [localhost/sid#7f4a0d1d2cf0][rid#7f4a0d684738/initial] (3) [perdir /var/www/html/application1/] strip per-dir prefix: /var/www/html/application1/common/assets/js/nav.min.js -> common/assets/js/nav.min.js
192.168.33.1 - - [27/Jan/2017:22:48:45 --0500] [localhost/sid#7f4a0d1d2cf0][rid#7f4a0d684738/initial] (3) [perdir /var/www/html/application1/] applying pattern '^(.*)$' to uri 'common/assets/js/nav.min.js'
192.168.33.1 - - [27/Jan/2017:22:48:45 --0500] [localhost/sid#7f4a0d1d2cf0][rid#7f4a0d684738/initial] (2) [perdir /var/www/html/application1/] rewrite 'common/assets/js/nav.min.js' -> 'public/common/assets/js/nav.min.js'
192.168.33.1 - - [27/Jan/2017:22:48:45 --0500] [localhost/sid#7f4a0d1d2cf0][rid#7f4a0d684738/initial] (3) [perdir /var/www/html/application1/] add per-dir prefix: public/common/assets/js/nav.min.js -> /var/www/html/application1/public/common/assets/js/nav.min.js
192.168.33.1 - - [27/Jan/2017:22:48:45 --0500] [localhost/sid#7f4a0d1d2cf0][rid#7f4a0d684738/initial] (2) [perdir /var/www/html/application1/] strip document_root prefix: /var/www/html/application1/public/common/assets/js/nav.min.js -> /application1/public/common/assets/js/nav.min.js
192.168.33.1 - - [27/Jan/2017:22:48:45 --0500] [localhost/sid#7f4a0d1d2cf0][rid#7f4a0d684738/initial] (1) [perdir /var/www/html/application1/] internal redirect with /application1/public/common/assets/js/nav.min.js [INTERNAL REDIRECT]
192.168.33.1 - - [27/Jan/2017:22:48:45 --0500] [localhost/sid#7f4a0d1d2cf0][rid#7f4a0d676688/initial/redir#1] (1) [perdir /var/www/html/application1/public/] pass through /var/www/html/application1/public/common/assets/js/nav.min.js
This should do it:
RewriteEngine on
# Allow node_modules
RewriteCond $1 !^node_modules($|/)
# Rewrite everything to public except public
RewriteCond $1 !^public($|/)
RewriteRule ^(.*)$ public/$1 [L,QSA]
# 404 diret access to public
RewriteRule ^public/ - [L,R=404]
Got it working with two separate files.
.htaccess:
<IfModule mod_rewrite.c>
RewriteEngine on
# Allow node_modules
RewriteRule ^node_modules($|/) - [L]
# Rewrite everything to public
RewriteRule ^(.*)$ public/$1 [L,QSA]
</IfModule>
.htaccess inside public:
<IfModule mod_rewrite.c>
RewriteEngine on
# pass-through if another rewrite rule has been applied already
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule .* - [S=1] # Skip the next rule
RewriteRule ^ - [L,R=404]
# ...additional rules here as needed
</IfModule>
[L] can have been used instead of [S=1] in the second file if there are no additional rules.
This question gave me the idea with "pass-through if redirect".
Also thanks to #SuperDuperApps for the debugging hint with RewriteLogLevel and the original answer with the [END] flag that may have worked if I had Apache 2.4.

RewriteCond -d .htaccess failing but directory exists

I am trying to conditionally rewrite the directory path of a URI if an override exists and the override directory exists in an Apache 2.2 .htaccess file running on RHEL5.
I am doing this by conditionally setting an environment variable to a directory and then later I am checking if the environment variable is set and the directory exists. This is for a Drupal site but not sure that matters.
RewriteCond %{HTTP_HOST} qa-public.sample.com
RewriteRule ^ - [ENV=publicFiles:sites/qa-public.sample.com/files]
...
RewriteCond %{ENV:publicFiles} !^$
RewriteCond %{ENV:publicFiles} -d
RewriteRule ^sites/default/files(/.*)$ %{ENV:publicFiles}$1 [PT]
I turned on rewrite logging to level 7.
10.20.67.192 - - [27/Feb/2014:13:16:34 --0500] [qa-public.sample.com/sid#7f631331ecd8][rid#7f631360e568/initial] (4) [perdir /var/www/qa-public/] RewriteCond: input='sites/qa-public.sample.com' pattern='!^$' => matched
10.20.67.192 - - [27/Feb/2014:13:16:34 --0500] [qa-public.sample.com/sid#7f631331ecd8][rid#7f631360e568/initial] (4) [perdir /var/www/qa-public/] RewriteCond: input='sites/qa-public.sample.com' pattern='-d' => not-matched
I used the output of perdir and input to verify it exists. It is a symbolic link pointing to a directory.
$ ls -l /var/www/qa-public/sites/qa-public.sample.com/files
lrwxrwxrwx 1 XXXXXX YYYYYY 27 Feb 13 14:20 /var/www/qa-public/sites/qa-public.sample.com/files -> /usr/local/files-qa/
I have also tried -l and -x. I have also tried other non-linked directories.
I have tried adding a / before and/or after the directory in the RewriteCond.
I can remove the -d condition and Apache will serve the file.
Thanks,
Wes.
Try this condition:
RewriteCond %{DOCUMENT_ROOT}/%{ENV:publicFiles} -d

Trouble with serving local content while using RewriteRule [P]

I'm trying to write rules that will serve files on the new server, while proxying files that don't exist, to the old server. The proxy rules work fine, sending missing files and directories to the old server.
The problem I'm having is new-server.example.com/blah (/blah/ exists on the new server) is passed through to the proxy rules and routed to the old server.
The reason for attempting the skip is because new-server.example.com/blah falls through to the "proxy section" and passes new-server.example.com/blah/index.php. Index.php doesn't exist on the new server, index.html does. The "proxy section" doesn't follow all the index file possibilities in DirectoryIndex, it just looks at the first one.
So I end up with error message, "The requested URL /blah/index.php was not found on this server."
How can this be written so it actually works? -- Thanks.
RewriteEngine On
# skip, proxy section
RewriteCond /var/www/html%{REQUEST_FILENAME} -f [OR]
RewriteCond /var/www/html%{REQUEST_FILENAME} -d
RewriteRule .? - [S=4]
# proxy section
RewriteCond /var/www/html%{REQUEST_FILENAME} !-f
RewriteCond /var/www/html%{REQUEST_FILENAME} !-d
RewriteRule ^/(.*) http://old-server.example.com/$1 [P]
ProxyPassReverse / http://old-server.example.com/
# rewrite log
pass through /index.php
init rewrite engine with requested uri /
applying pattern '.?' to uri '/'
RewriteCond: input='/var/www/html/' pattern='-f' => not-matched
RewriteCond: input='/var/www/html/' pattern='-d' => matched
pass through /
init rewrite engine with requested uri /index.php
applying pattern '.?' to uri '/index.php'
RewriteCond: input='/var/www/html/index.php' pattern='-f' => matched
pass through /index.php
init rewrite engine with requested uri /blah/
applying pattern '.?' to uri '/blah/'
RewriteCond: input='/var/www/html/blah/' pattern='-f' => not-matched
RewriteCond: input='/var/www/html/blah/' pattern='-d' => matched
pass through /blah/
init rewrite engine with requested uri /blah/index.php
applying pattern '.?' to uri '/blah/index.php'
RewriteCond: input='/var/www/html/blah/index.php' pattern='-f' => not-matched
RewriteCond: input='/var/www/html/blah/index.php' pattern='-d' => not-matched
applying pattern '^/(.*)' to uri '/blah/index.php'
RewriteCond: input='/var/www/html/blah/index.php' pattern='!-f' => matched
RewriteCond: input='/var/www/html/blah/index.php' pattern='!-d' => matched
rewrite '/blah/index.php' -> 'http://old-server.example.com/blah/index.php'
forcing proxy-throughput with http://old-server.example.com/blah/index.php
go-ahead with proxy request proxy:http://old-server.example.com/blah/index.php [OK]
This is the way Apache has worked since version 2.0: It gets a request, runs that request through all of the RewriteRules, then if the resulting request is a directory, it tries to see if the first DirectoryIndex will work, so it runs that through the RewriteRules and tries to serve the result. If the first DirectoryIndex entry doesn't work (i.e. it gets to the point where Apache would have served a 404), the server tries again with the next entry and so on. Your problem, obviously, is that the proxy rules latch on to the nonexistent first DirectoryIndex value and try to send it through the reverse proxy.
I haven't found a general way to fix this behavior server-wide, but there is a workaround. Use either a <Location> section in your httpd.conf file or a .htaccess file and override DirectoryIndex for that location.
In your case, create the file /var/www/html/blah/.htaccess and put the following into it:
DirectoryIndex index.html

Apache Mod Rewrite for Pretty URLs isn't working

I'm trying to figure out how to do an apache mod_rewrite to remap $_GET.
What I'm trying to accomplish:
Currently, to get to the page one would have to go to
http://www.domain.com/index.php?URL=pages/the-page.php
I would like this to work in 2 ways:
If someone goes to domain.com/the-page, it takes them to the above but keeps it looking like this. Secondly, if someone goes to the http://www.domain.com/index.php?URL=pages/the-page.php, it will still show as domain.com/the-page, keeping the URL short and clean.
Most Recently Tried Code
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/index\.php$
RewriteCond %{QUERY_STRING} URL=pages/([a-z0-9-_]+)\.php$
RewriteRule ^(.*) /%1
I'm pretty sure I setup everything right in the apache httpd.conf. I'm using XAMPP to test locally, restarted apache on changes, still nothing. Where am I going wrong?
I would prefer to handle this in .htaccess
I am using XAMPP localhost and trying on live server.
Log File:
127.0.0.1 - - [05/Apr/2013:16:50:43 --0400] [localhost/sid#2f3140][rid#3b14068/initial] (3) [perdir C:/xampp/htdocs/cdi/] strip per-dir prefix: C:/xampp/htdocs/cdi/index.php -> index.php
127.0.0.1 - - [05/Apr/2013:16:50:43 --0400] [localhost/sid#2f3140][rid#3b14068/initial] (3) [perdir C:/xampp/htdocs/cdi/] applying pattern '^(.*)' to uri 'index.php'
127.0.0.1 - - [05/Apr/2013:16:50:43 --0400] [localhost/sid#2f3140][rid#3b14068/initial] (1) [perdir C:/xampp/htdocs/cdi/] pass through C:/xampp/htdocs/cdi/index.php
Updated log with Olaf's script (last rule commented out)
127.0.0.1 - - [05/Apr/2013:20:02:24 --0400] [localhost/sid#2e3140][rid#3b14090/initial] (3) [perdir C:/xampp/htdocs/cdi/] strip per-dir prefix: C:/xampp/htdocs/cdi/index.php -> index.php
127.0.0.1 - - [05/Apr/2013:20:02:24 --0400] [localhost/sid#2e3140][rid#3b14090/initial] (3) [perdir C:/xampp/htdocs/cdi/] applying pattern '^' to uri 'index.php'
127.0.0.1 - - [05/Apr/2013:20:02:24 --0400] [localhost/sid#2e3140][rid#3b14090/initial] (3) [perdir C:/xampp/htdocs/cdi/] strip per-dir prefix: C:/xampp/htdocs/cdi/index.php -> index.php
127.0.0.1 - - [05/Apr/2013:20:02:24 --0400] [localhost/sid#2e3140][rid#3b14090/initial] (3) [perdir C:/xampp/htdocs/cdi/] applying pattern '^index\.php$' to uri 'index.php'
127.0.0.1 - - [05/Apr/2013:20:02:24 --0400] [localhost/sid#2e3140][rid#3b14090/initial] (2) [perdir C:/xampp/htdocs/cdi/] rewrite 'index.php' -> '/newhome?'
127.0.0.1 - - [05/Apr/2013:20:02:24 --0400] [localhost/sid#2e3140][rid#3b14090/initial] (3) split uri=/newhome? -> uri=/newhome, args=<none>
127.0.0.1 - - [05/Apr/2013:20:02:24 --0400] [localhost/sid#2e3140][rid#3b14090/initial] (2) [perdir C:/xampp/htdocs/cdi/] explicitly forcing redirect with http://localhost/newhome <--this one seems to be causing the issue
127.0.0.1 - - [05/Apr/2013:20:02:24 --0400] [localhost/sid#2e3140][rid#3b14090/initial] (1) [perdir C:/xampp/htdocs/cdi/] escaping http://localhost/newhome for redirect
127.0.0.1 - - [05/Apr/2013:20:02:24 --0400] [localhost/sid#2e3140][rid#3b14090/initial] (1) [perdir C:/xampp/htdocs/cdi/] redirect to http://localhost/newhome [REDIRECT/302]
Thank you everyone that is helping. I've spent 2 days trying to get this to work!!!
Basically, you need two rules. One rule to redirect the client to a clean URL and another to internally rewrite the pretty URL to the real content via index.php.
Assuming the index.php and .htaccess is in a directory cdi
RewriteEngine on
# prevent endless loop
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule ^ - [L]
# redirect the client
RewriteCond %{QUERY_STRING} URL=pages/(.+?)\.php
RewriteRule ^index\.php$ /cdi/%1? [R,L]
# exclude rewriting all files located in /cdi/files
RewriteCond %{REQUEST_URI} !^/cdi/files/
# rewrite to real content
RewriteRule ^.*$ /cdi/index.php?URL=pages/$0.php [L]
Update:
When the request is /cdi/index.php?URL=pages/abc.php, the second rule extracts the needed URL part and redirects the client to the new URL path. The client then requests the new URL /cdi/abc and the third rule takes this and does an internal rewrite to the real content.
This all works fine as it should, but would rewrite and redirect indefinitely. To break this endless rule, the first rule checks the environment %{ENV:...}, if the request was already redirected REDIRECT_STATUS and then stops the cycle with the RewriteRule
RewriteRule ^ - [L]
which matches everything ^ and does no substitution, but ends the rewrite cycle with the flag [L]
Instead of using the system provided environment STATUS/REDIRECT_STATUS, you can also set a variable yourself with the flag E=SEO:1 for example, and then test for this variable with
RewriteCond %{ENV:REDIRECT_SEO} 1
For the REDIRECT_ prefix, see Available Variables.
You could try this:
RewriteRule ^/([a-z0-9_-]{1,40})/?$ index.php?URL=pages/$1.php
Though ideally you might want to get rid of the "pages/" part of the query string variable, as this fixed constant could be handled by the index.php script.
You approach seems fine but your RewriteCond doesn't match your requirements:
RewriteCond %{REQUEST_URI} ^index.php?URL=pages
means "rewrite the URL if someone requests something that starts with 'index.php"—but that's not what anyone will be requesting. You want your visitors to request pretty URLs.
If your server only needs to serve those requests for /the-page, you can drop the condition entirely. Then any URL will be rewritten. (Note: This might not be what you want!)
Otherwise, the condition should read something like this:
RewriteCond %{REQUEST_URI} ^[a-z0-9-_]{1,40}
If you don't want to mess with regular expressions, you could also try this:
RewriteCond %{REQUEST_FILENAME} !-f
which means "if the user requests a URL for which no file can be found, rewrite the URL according to the upcoming RewriteRule."
If you want the group ([0-9]+) to be alphabetic then just change it to ([a-z]+) and if you've wanted it to be alphanumeric, then change it to ([a-z0-9]+), and ([a-z0-9-_]+) if with a hyphen and an underscore. If you've wanted it to set their limits manually, you can do that with this format ([a-z0-9-_]{1,40}). Do you see, the plus sign is gone, for it limited the [chars] with 1 to anything, and the {1,40} limited the [chars] with 1 to 40, you can either change it.
Do you know what the real problem is? Is my stress.. Imagine even I know that you want to remap /$var into /index.php?URL=pages/$var.php I'm still trying giving you a wrong information that will rewrite /index.php?URL=pages/$var.php into /$var. I just have realize that after my 4 hours sleep. Did you see what's happening when the time of your sleep isn't right? Maybe a rule I would gives to you when my brain's in functioning well, was:
RewriteRule ^([a-z0-9-_]+)/?$ /index.php?URL=pages/$1.php
Why did the viewers letting this to happened.. My previous codes are needed to be voted down.

rewrite URL for PUT request

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>
There is, with mod_rewrite:
RewriteEngine on
RewriteCond %{REQUEST_METHOD} =PUT
RewriteRule ^/test/(.*) /$1