Tags

,


The issue….

Recently I had to call a variety of PHP files without specifying the extension as .php This was obviously a rewite rule of some kind and after some effort I managed to get a rule working that allowed a URL such as: http://localhost/test to call test.php

The .htaccess file

Options +FollowSymlinks
RewriteEngine on
Rewritebase /base/to/php/files
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) $1.php

The .htaccess file needs to reside in the directory where the PHP programs reside and note that the “.” is significant!

The Rewritebase narrows down the effect of the rule to the particular directory where the files reside.

Notes

I tried this on another server and it failed, it appears you need to ensure “AllowOveride All” is enabled in the sites VirtualHost config file.

A sample of a Dockerui VirtualHost file:

#cat /etc/httpd/conf.d/dockerui.conf

<VirtualHost *:80>
    ServerName dockerui.test.com
    DocumentRoot /var/www/dockerui/dist
    <Directory /var/www/dockerui/dist>
        Options FollowSymLinks
        AllowOverride All
    </directory>
    DirectoryIndex index.html
    ProxyPass /dockerapi/ http://127.0.0.1:4243/
    ProxyPassReverse /dockerapi/ http://127.0.0.1:4243/
</VirtualHost>

Enjoy!

 

Advertisements