【问题标题】:localhost remove HTML extension [closed]本地主机删除 HTML 扩展名 [关闭]
【发布时间】:2013-10-20 19:32:31
【问题描述】:

我一直在尝试使用 htaccess 清理我的网址,但我无法让它在我的本地主机上工作。

我的网址:localhost/index.html

这是我 www 文件夹中的默认 htaccess 文件。

#------------------------------------------------------------------------------
# To allow execution of cgi scripts in this directory uncomment next two lines.
#------------------------------------------------------------------------------

AddType application/x-httpd-php .html .htm .php
AddHandler cgi-script .pl .cgi
Options +ExecCGI +FollowSymLinks

【问题讨论】:

  • 请分享您的尝试及其结果。即使它们不起作用,它们也向我们表明您已尝试自己解决问题,它使我们能够判断出了什么问题。见the SO question checklist

标签: html .htaccess localhost


【解决方案1】:

将此添加到您的网络根/www 目录中的.htaccess

Options +ExecCGI +FollowSymLinks -MultiViews

RewriteEngine on
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.*)$ /$1.html [L]

现在http://localhost/page.html 也可以作为http://localhost/page 访问。


请注意,我之前错过了添加RewriteCond %{REQUEST_FILENAME} !-d。此条件确保任何名为/page 的现有目录不会被page.html 覆盖。

【讨论】:

  • +1 但我也会添加RewriteCond %{REQUEST_FILENAME} !-d 条件
  • @anubhava 谢谢。已更新。
猜你喜欢
  • 2021-07-12
  • 2014-06-29
  • 2011-03-17
  • 2017-08-28
  • 1970-01-01
  • 2015-03-20
  • 2022-03-04
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多