0

Is it bad to use:

ForceType application/x-httpd-php

and to save files without a file extention (e.g. index instead of index.php)? The intention is to hide/remove .php from the URL and to stop users from manually putting e.g. /example.php.

2
  • 5
    use .htaccess to hide the extension. Commented Dec 24, 2013 at 20:25
  • Yes, I have WAMP installed on Windows and it works for me. Commented Dec 24, 2013 at 20:28

3 Answers 3

2

To remove the file extension, add this to the .htaccess :

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php

change .php to the proper file extension

new link :

<a href="file">link text</a>

Edit :

Save your files as index.php, about.php, and so on

Sign up to request clarification or add additional context in comments.

3 Comments

Does this work for files in sub-directories? e.g. /folder/script => /folder/script.php?
If you place this in the .htaccess file of your root, it will apply to all enclosing subfolders. This means the .htaccess file in root will affect /sub/file.php (now /sub/file), but /sub/.htaccess will not affect /file.php
.htaccess carry onto subfolders. Perhaps your files are a different extension? If all your files are the same extension (ie .php), try copying your .htaccess file to the subfolder and see if it solves your issue.
1

Yes. Yes it is bad.

The right way to do that is by using mod_rewrite and .htaccess files.

Comments

0

Its not good practice to change extension as it will need configuration for web server each time and so its a portability issue.

You should use .htaccess directives to setup any level of customization. And in best practice you can route all requests to index.php to avoid direct access of php files.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.