How to hide PHP file extension without using .htaccess

后端 未结 2 1527
谎友^
谎友^ 2020-12-06 15:22

How am I able to hide a .php extension in an URL address, so that this address,

http://www.thesite.com/somefile.php

would look like

相关标签:
2条回答
  • 2020-12-06 16:03

    Although you specifically said no, using the .htaccess file would remove the .php extension from all PHP files in all subdirectories in a site. I think that is what you are going for.

    <IfModule mod_rewrite.c>
      RewriteEngine on
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteCond %{REQUEST_FILENAME}\.php -f
      RewriteRule ^(.*)$ $1.php
    </IfModule>
    

    Putting that into the .htaccess file will remove all the .php file extensions. Or you could put it directly into the webserver's configuration files.

    0 讨论(0)
  • 2020-12-06 16:07

    You can achieve this with URL rewriting. If you don't want to use .htaccess, you can write the rule in your host configuration file.

    0 讨论(0)
提交回复
热议问题