问题描述
我如何在URL地址中隐藏.php扩展名,以便该地址,
How am I able to hide a .php extension in an URL address, so that this address,
http://www.thesite.com/somefile.php
看起来像
http://www.thesite.com/somefile
不使用.htaccess文件.这样做的原因是因为我有很多目录,并且想隐藏每个目录中所有这些文件的扩展名.我试图将expose_php
设置为off,但这仍然失败,并显示错误404.
without the use of the .htaccess file. The reason for that being because I have many directories and would want to hide the extension on all those files in every directory. I have tried to set expose_php
to off, and this still fails with error 404.
我正在使用PHP 5.3.10和Apache服务器.
I am using PHP 5.3.10 and Apache server.
推荐答案
尽管您明确表示不,但使用.htaccess
文件将删除站点中所有子目录中所有PHP文件中的.php
扩展名.我想这就是你要的.
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>
将其放入.htaccess
文件将删除所有.php文件扩展名. 或者,您可以将其直接放入Web服务器的配置文件中.
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.
这篇关于如何在不使用.htaccess的情况下隐藏PHP文件扩展名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!