使用 apache conf 从 url 中删除 .html/.php

Removing .html/.php from url with apache conf

我设法通过 htaccess 文件删除了 .extension,但我想知道这是否可以通过 apache2.conf 或其他一些文件而不使用 .htaccess 文件。

Exp.

example.com/example

而不是

example.com/example.html

您可以在 Apache conf 文件中使用这 2 个规则:

RewriteCond %{THE_REQUEST} \s/+(.+?)\.html[\s?] [NC]
RewriteRule ^ /%1 [R=302,L,NE]

# To internally forward /dir/file to /dir/file.html
RewriteCond %{DOCUMENT_ROOT}/\.html -f [NC]
RewriteRule ^(.+?)/?$ .html [L]