0

I have a web application, and it has a RESTful PHP backend that uses Zend framework (which does its own URL rewriting magic).

The problem is, my backend's entry-page is api.php and the endpoints look like:

api.php/resource1
api.php/resource2/id

All I want to do is remove the .php file extension so my URLs look a little cleaner.

Is there any way of doing this without removing the file extension from the PHP file?

2

Rewrite rule in .htaccess:

RewriteRule  ^test(/.*)?$ test.php?path=$1

Contents of test.php:

<?php 
 if($_GET['path']){
   echo ($_GET['path']);
 }
?>

Then when I hit /test/foo/bar on my server, the PHP page prints out /foo/bar.

  • Sorry dude, doesn't work for me. I'm pretty sure this is something to do with .htaccess rules conflicting with Zend Framework's own URL rewriting stuff. After adding your rule to my .htaccess file, it just gives me a 404 :( – Hassan Khan May 27 '13 at 16:06
0

Try this to just remove .php:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /.php/$1 [L]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.