【问题标题】:Remove extensions for both .html and .php in apache在 apache 中删除 .html 和 .php 的扩展名
【发布时间】:2018-10-10 22:23:40
【问题描述】:

代码混合在一起,我在同一个文件夹中有 .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 文件中的第一组条件。鉴于您所说的条件,Apache 无法知道它应该寻找 html 文件还是 php 文件。
  • 是的,这就是问题所在。如果条件为假,我不知道如何跳过第一条规则。
  • 尝试将大写 -F 改为小写 -f。另请查看this question
  • @Dave 我用小写字母 -f 试过了,但还是没用,我确实关闭了多视图

标签: php html apache mod-rewrite url-rewriting


【解决方案1】:

你可以在 .htaccess 文件上试试这个:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule (.*) $1.php [L]
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule (.*) $1.html [L]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-03-04
    • 1970-01-01
    • 2013-03-13
    • 2018-06-25
    • 1970-01-01
    • 2013-10-11
    • 2020-08-11
    相关资源
    最近更新 更多