dafydd
dafydd

Reputation: 275

Treat an incomplete filename in a URL as PHP?

I didn't write this web code. I just have to deploy it....

The $WEBROOT directory includes index.php and login.php, among others.

The automatic redirect URL from index.php (which successfully executes when just the domain URL is requested) is http://$HOST.$DOMAIN/login?p=$VALUE This returns the code 404.

If I manually change the URL to http://$HOST.$DOMAIN/login.php?p=$VALUE

the login page successfully appears.

My first problem is I don't know what keywords to search for in the Apache documentation for this. This question seems close. But, my actual files have the .php extension. My problem is that I have to assume all of the URLs will just request file and not file.php.

How do I tell Apache to look for file.php before it returns a 404 for not finding file?

Upvotes: 3

Views: 101

Answers (1)

Kidus
Kidus

Reputation: 1833

Create a file named .htaccess with the following content inside the folder your .php files are in:

#turn on url rewriting 
RewriteEngine on

#remove the need for .php extention 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}\.php -f 
RewriteRule ^(.*)$ $1.php

Upvotes: 5

Related Questions