简体   繁体   English

如何更改网站页面的.php扩展名?

[英]How to change .php extension of website pages?

I have a website running on PHP. 我有一个在PHP上运行的网站。 I want to remove the .php suffix from all of my webpages in such way that the user doesn't get to know what server side language is running. 我想从所有网页中删除.php后缀,以使用户不知道正在运行哪种服务器端语言。

How do I edit the displayed address in the address bar to not show the .php ? 如何在地址栏中编辑显示的地址以不显示.php

With mod_rewrite in .htaccess: 在.htaccess中使用mod_rewrite

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L] 

Apache has a feature, 'MultiViews' that allows the server to choose the correct extension when none is supplied. Apache具有“ MultiViews”功能,当没有提供扩展名时,允许服务器选择正确的扩展名。 In your .htaccess or httpd.conf , you can add this: 在您的.htaccesshttpd.conf ,可以添加以下内容:

Options MultiViews

If you have a file at /path/to/blah.php , it can be accessed as merely /path/to/blah . 如果您在/path/to/blah.php有一个文件,则可以仅通过/path/to/blah访问该文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM