仅当文件存在时才将 .html 映射到 .php
这是我的规则:
RewriteRule ^(.*)\.html$ /$1.php
这适用于服务器上有匹配的物理 .php 文件的“虚拟”.html url。
但是,当我输入实际 .html 文件的 url 时,我无法访问它,因为上面的规则当然是告诉服务器查找物理 .php 文件。
那么如何修改规则以仅在存在物理 .php 文件时才应用于 URL,否则按原样加载 .html 文件。
Here is my rule:
RewriteRule ^(.*)\.html$ /$1.php
This works for "virtual" .html urls which have a matching physical .php file on the server.
However when I type in a url for an actual .html file, I cannot access it, because of course the rule above is telling the server to look for a physical .php file.
So how can the rule be modified to apply to URLs only if there is a physical .php file, else load the .html file as is.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个规则:
Try this rule: