避免使用.php扩展名

实现URL路径到.php扩展名转换的.htaccess代码
本文介绍如何使用.htaccess代码将URL路径中的无扩展名部分自动添加.php扩展名,以简化网站设计和语言切换过程。

For example:

http://www.example.com/contact

http://www.example.com/contact.php

Not only does the first URL look cleaner, but if I decided to switch languages, it would be less of an issue.

 

So how does one implement this? Here is the .htaccess code I found works best:

 

不仅第一的网址看起来更简洁,但如果我决定切换语言,这将不再是一个问题。

 

那么,如何实现呢?下面是我发现最好。htaccess代码:


# If requested URL-path plus ".php" exists as a file
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
# Rewrite to append ".php" to extensionless URL-path
RewriteRule ^(([^/]+/)*[^.]+)$ /$1.php [L]

http://www.webmasterworld.com/apache/3609508.htm

转载于:https://www.cnblogs.com/cnsg/archive/2012/11/01/2749898.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值