如何使example.com/about显示example.com/about.html? (Apache2的)

尝试使用example.com/about show example.com/about.html,而不必将url更改为/about.html时,最佳select是什么? 现在我正在尝试下面的代码,它只是返回一个404错误。

RewriteRule ^/about$ https://example.com/about.html [R=301,L] 

编辑#1 W3DK我目前有多视图启用,但我仍然得到一个404错误。 这是我当前在VirtualHost中的当前设置

 <Directory /var/www/public_html> Options All +MultiViews AllowOverride All Order allow,deny allow from all </Directory> 

而不是使用mod_rewrite在内部重写请求,你可以使用MultiViews(mod_negotiation)来代替:

 Options +MultiViews 

mod_rewrite允许你做更复杂的URL重写,但是,如果你正在做的是删除文件扩展名,那么MultiViews就足够了 – 这是它的目的。

当您为/about (在有效目录中没有扩展名的URL /文件)提出请求时,启用MultiViews后,mod_negotiation将search与期望的MIMEtypes匹配的文件,并将其作为内部请求返回。

更新:

 Options All +MultiViews 

这是不合法的语法(我假设你必须在Apache 2.2上,因为这会在Apache 2.4上启动时发生错误)。 如Apache文档中所述 :

警告
Options+-混合使用不是有效的语法,可能会导致意外的结果。

要expressionAllMultiViews您需要两个指令:

 Options All Options +MultiViews 

All是默认的(在Apache 2.2上),所以这可能不是必需的。 但是,最好仅在单个指令中指定所需的选项,例如:

 Options FollowSymLinks Includes MultiViews 

你能不能像这样尝试一下:我认为它会起作用

 Options +FollowSymLinks RewriteEngine on RewriteRule ^about$ https://example.com/about.html [R=301,L] 

你也可以使用redirect:

 Redirect 301 /about http://example.com/about.html Redirect 301 /any_dir/about http://example.com/about.html