Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

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?

share|improve this question

2 Answers 2

up vote 2 down vote accepted

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.

share|improve this answer
    
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

Try this to just remove .php:

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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