How to execute a PHP web page without the .php extension in the URL?

后端 未结 6 644
野趣味
野趣味 2021-02-01 06:24

Sorry for noob question, can\'t understand from what I should search.

I\'m making a site with that page product.php?id=777
I\'d like it to be pro

6条回答
  •  猫巷女王i
    2021-02-01 07:07

    If you don't want to use mod_rewrite (I didn't) and the other answers didn't seem to work for you (they didn't for me). Then you might try this is you're running on Apache 2.4+.

    The more insecure version: make anything without an extension run as a PHP file (this isn't so bad if, like my implementation you only have a single file for the whole server, but would still leave you open to arbitrary execution if someone were able to write a file into that directory... then again, if they can write a file, they could give it a PHP extension, so not really sure if this truly broadens your exposure.)

    
        ForceType application/x-httpd-php
    
    

    Put this in either an .htaccess file for your directory (assuming you have those enabled) or put it directly in the piece in your host definition.

    If you want to make it more specific (and maybe more secure) you can just replace the regex with something more concrete:

    
        ForceType application/x-httpd-php
    
    

    Edit: You do not need regex if you want to target only one file. Use this instead

    
        ForceType application/x-httpd-php
    
    

    Then just restart Apache and you're good to go!

提交回复
热议问题