views:

505

answers:

1

I'm trying to build an extremely simple RESTful test rig for an app I'm working on. I'm using .htaccess to redirect urls to my controller script where I will parse the urls to handle the logic.

I have the redirect working, but the problem is that if I do a POST/PUT/DELETE, Firebug shows my requests going to the test rig properly, but I get a 301 redirect response and then a 2nd GET response.

How can I use htaccess for my url redirection without it sending a 301 to the browser?

This is the .htaccess I'm using now:

RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1
+4  A: 

Try something like this:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

This will redirect unless the file asked for exists(such as an image or CSS file). I frequently use these rules and I've never have run into a 301.

Check that your PHP script isn't changing the response to a 301.

Kekoa
Gracias. Your updated rewrite helped. I also had an incomplete client-side handler initiating the requests. Now fixed both, working wonderfully.
Geuis
If there a way to also allow for "index.html" remaining as default if no filename is given at all?
michael