php - 在 apache 中删除 .html 和 .php 的扩展名
问题描述
代码混合在一起,我在同一个文件夹中有 .html 和 .php 。永远不会有相同的名称但不同的扩展名。我有一些应该可以工作但没有的代码。html 部分有效,但是当我尝试请求没有扩展名的 PHP 页面时,URL 会给出 404
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -F
RewriteRule ^(.*)$ $1.html
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -F
RewriteRule ^(.*)$ $1.php
解决方案
你可以在 .htaccess 文件上试试这个:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule (.*) $1.php [L]
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule (.*) $1.html [L]
推荐阅读
- docker - Docker 容器显示入口点命令“未找到”
- python - 如何按多个条件过滤熊猫数据框列
- ruby - Jekyll 安装问题。Jekyll 使用 bash 终端安装,但当我尝试检查版本时输出“jekyll:找不到命令”错误
- java - 由于不可访问的部署目录,Keycloak 启动时扫描失败:/opt/jboss/keycloak/standalone/deployments
- node.js - 404 gh-pages 单页 React App 部署后
- css - 从 YouTube 直播页面中删除边距
- android - Android:防止歌曲在 MediaPlayer 中循环播放。OnCompletionListener 未触发
- c++ - 基于堆栈的平衡括号问题
- android - 从偏好中移除涟漪效应
- algorithm - 如何删除此图像中建筑物中的超出部分?