apache - 如何使用 .htaccess 规则将 .php 重写为 .html?
问题描述
我尝试过,但失败了。原始网址
https://www.sitename.com/user/login/index.php
https://www.sitename.com/user/dashboard/index.php
浏览器应显示的 URL
https://www.sitename.com/user/login.html
https://www.sitename.com/user/dashboard.html
这是我尝试过的,但它不起作用
RewriteEngine on
RewriteBase /
RewriteCond %{THE_REQUEST} (.*)\.php
RewriteRule ^(.*)\.php http://%{HTTP_HOST}/user/$1.html [R=301,L]
RewriteCond %{THE_REQUEST} (.*)\.html
RewriteRule ^(.*)\.html http://%{HTTP_HOST}/user/$1.php [L]
解决方案
请您尝试以下操作。使用您展示的样本进行编写和测试。请确保在测试 URL 之前清除浏览器缓存。
RewriteEngine ON
RewriteCond %{REQUEST_URI} ^/([^/]*)/([^.]*)\.html/?$ [NC]
RewriteRule ^(.*)$ %1/%2/index.php [L]
推荐阅读
- azure-data-factory-2 - 在 Azure 数据工厂中运行数据流比在 Azure SSIS 数据流中运行慢 4 倍
- node.js - Nodejs谷歌认证休息api
- python - 将变量传递给 MySQL 查询
- python - 如何将具有较大时间增量的熊猫记录拆分为具有较小时间增量的多个记录?
- python - 使用线程时对象不可调用?
- redis - volatile-lru 是否会驱逐所有具有相同 ttl 的键?
- python - 错误:NameError:未定义名称“Caitlin”
- c - 是否可以使用“fopen”或“open”打开当前程序(argv[0])
- python - DRF- 从嵌套表示创建新对象会引发 TypeError
- python - 使用 Selenium 和 Firefox 实现配置文件和扩展数据