且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用 .htaccess 删除 .php 扩展名

更新时间:2021-12-26 01:25:37

Gumbo 在 Stack Overflow 问题中的回答 如何使用 Apache mod_rewrite 隐藏 .html 扩展名 应该可以正常工作.

Gumbo's answer in the Stack Overflow question How to hide the .html extension with Apache mod_rewrite should work fine.

重新 1) 将 .html 更改为 .php

Re 1) Change the .html to .php

Re a.) 是的,这是可能的,只需将 #tab 添加到 URL.

Re a.) Yup, that's possible, just add #tab to the URL.

Re b.) 可以使用 QSA(查询字符串追加),见下文.

Re b.) That's possible using QSA (Query String Append), see below.

应该也适用于子目录路径:

This should also work in a sub-directory path:

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule !.*.php$ %{REQUEST_FILENAME}.php [QSA,L]