Hide PHP from user

后端 未结 5 1709
粉色の甜心
粉色の甜心 2021-01-14 04:16

Is there a way to hide the fact that I\'m using PHP from my users? I wanted to do this for two reasons:

  • 1) So the links in the address bar look cleaner (like h
5条回答
  •  感情败类
    2021-01-14 04:38

    The best way to keep your PHP hidden from public access is to structure your folders accordingly. Best practice is to keep your library and application files at least one level up from the public folder, like:

    /application
        // application files
    /library
        // library and vendor files
    /public (aka public_html, htdocs etc)
        index.php
        .htaccess
        /css
        /images
        /js
    

    Use htaccess and mod_rewrite to route requests to the index.php file, which will then dispatch the request to the application.

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

    This way, you only have a single php file publicly accessible, which merely includes other files not available via any url

提交回复
热议问题