Mobile app version of vmapp.org
Login or Join
Holmes151

: Pretending a file is in subdirectory with .htaccess 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

@Holmes151

Posted in: #Apache2 #Htaccess #ModRewrite #UrlRewriting

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?

10.02% popularity Vote Up Vote Down


Login to follow query

More posts by @Holmes151

2 Comments

Sorted by latest first Latest Oldest Best

 

@BetL925

Try this to just remove .php:

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

10% popularity Vote Up Vote Down


 

@BetL925

Rewrite rule in .htaccess:

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


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.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme