php - 使用 mod_rewrite RewriteRule 重写所有查询以不需要 .php 扩展名

标签 php url mod-rewrite friendly-url

我希望所有查询都像

http://mysite.com/something/otherthing?foo=bar&x=y

改写为

http://mysite.com/something/otherthing.php?foo=bar&x=y

换句话说,只需将 .php 扩展名设置为通用的即可。

最佳答案

我会这样做。基本上,如果文件不存在,请尝试向其中添加 .php。

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ $1.php [QSA,L]

关于php - 使用 mod_rewrite RewriteRule 重写所有查询以不需要 .php 扩展名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/183921/

相关文章:

java - 通过编码从字符串创建 uri

swift - Alamofire 背景在模拟器上工作但不在设备上工作

php - ajax中的删除功能不起作用

regex - 使用正则表达式从 Perl 纯文本中提取 URL

apache - 前端加载 mod_rewrite 规则导致 index.php 加载两次

.htaccess - .htaccess-RewriteRules工作正常,但浏览器地址栏显示完整(不友好)URL

wordpress - .htaccess、mod_rewrite 和基本身份验证

java - 如何确认文件 getdata.php 存在于给定的 url 中

PHP Date() 显示不正确的时区

java - 使用 Android (Java) 将文件上传到 php 脚本。文件大小为 0,但没有错误。房间在服务器上仍然可用