如何从网站地址中删除文件扩展名? [英] How can I remove file extension from a website address?
问题描述
我正在设计一个网站.我希望我的网站地址如下图所示:
I am designing a website. I want my website address to look like the following image:
我不希望我的网站看起来像http://something.com/profile.php
.
我希望有人打开我的网站时在地址栏中删除.php
扩展名.换句话说,我希望我的网站像: http://something.com/profile
I don't want my website to look like http://something.com/profile.php
.
I want the .php
extension to be removed in the address bar when someone opens my website. In other words, I want my website to be like: http://something.com/profile
作为第二个示例,您可以查看Stack Overflow网站地址本身.
As a second example, you can look at the Stack Overflow website address itself.
我该如何完成?
推荐答案
只需将.htaccess文件添加到您网站的根文件夹(例如/home/domains/domain.com/htdocs/)中,其内容如下:
Just add an .htaccess file to the root folder of your site (for example, /home/domains/domain.com/htdocs/) with the following content:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
这篇关于如何从网站地址中删除文件扩展名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!