3

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
GEOCHET
  • 21,119
  • 15
  • 74
  • 98
Geuis
  • 41,122
  • 56
  • 157
  • 219

1 Answers1

4

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
  • 27,892
  • 14
  • 72
  • 91
  • Gracias. Your updated rewrite helped. I also had an incomplete client-side handler initiating the requests. Now fixed both, working wonderfully. – Geuis May 19 '09 at 00:43
  • If there a way to also allow for "index.html" remaining as default if no filename is given at all? – donohoe Oct 19 '10 at 14:07