Hack Forums
[PHP] PHP open file without .php extension - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Web Development (https://hackforums.net/forumdisplay.php?fid=183)
+---- Thread: [PHP] PHP open file without .php extension (/showthread.php?tid=6049288)



PHP open file without .php extension - Bulgarian - Feb 13, 2020

My friend has a project that he wanted me to work on while he is on vacation.
He sent me his code, I connected the database and set up the site.

On some pages, particular modules don't open for me.

example code:
PHP Code

<?php 
$url 
= base_url+'includes/actions/autocomplete?module=measurements 

To make it work, I need to add the .php extension like so:
PHP Code

<?php 
$url 
= base_url+'includes/actions/autocomplete.php?module=measurements 

Why does it work for him without the extension and not for me?
Does it have to do with the apache settings?


RE: PHP open file without .php extension - Backbone - Feb 14, 2020

Maybe he got this on his .htaccess
Code
IndexIgnore * # prevent directory listing

Order deny,allow
Allow from *

# ------------------------------------------
# Rewrite so that php extentions are not shown
RewriteEngine on

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

I get those code from: stackoverflow.com/a/32140158
You might also want to read this topic about url rewritting: stackoverflow.com/questions/16388959/url-rewriting-with-php


RE: PHP open file without .php extension - AelonHunt - Feb 18, 2020

Without looking into the code its hard to answer. As @Backbone said, your friend may be using .htaccess


RE: PHP open file without .php extension - Shisho - Feb 18, 2020

You may need to give rewrite permissions to the public directory for the virtual host and then enable mod_rewrite and check for a valid .htaccess file. If all these things are there you should be able to do what you want with a URL.


RE: PHP open file without .php extension - Bulgarian - Feb 20, 2020

@Backbone

This worked for me! Thank you. I tried looking on google but I guess I didn't know how to word my question.

@Yani

To be honest, I'm not sure when I got this code from, I think I just made it up real quick.


RE: PHP open file without .php extension - Backbone - Feb 21, 2020

No problem.
I'll be more active here so if you have any question, just post it here.