【问题标题】:httpd.conf commands to .htaccesshttpd.conf 命令到 .htaccess
【发布时间】:2012-02-02 20:19:54
【问题描述】:

我使用 httpd.conf 和 mod_rewrite 从网页中删除文件扩展名....

我在 httpd.conf 中使用的代码是

    <IfModule mod_rewrite.c>
       Options +FollowSymLinks
       Options +Indexes
       RewriteEngine On
       RewriteCond %{SCRIPT_FILENAME} !-d
       RewriteRule ^([^\.]+)$ $1.html [NC,L]
    </IfModule>

这在我的带有 .htaccess 文件的外部服务器上不起作用,而且我无权访问 httpd.conf 文件....

任何想法如何更改命令,以便我可以使用 .htaccess 删除 url 中的所有 .html ............

提前感谢:D

【问题讨论】:

  • 您测试了哪些 URL 以确定它不起作用,结果如何?
  • 如果该代码在 .htaccess 文件中,它只会加载错误页面,404.... 我知道 htaccess 和 httpd.conf 的代码不同,并尝试逐行删除,我认为问题出在 RewriteRule.... 行
  • 我已经为我的网站测试了几乎所有的网址,无论有没有页面扩展......没有喜悦

标签: .htaccess mod-rewrite filenames httpd.conf


【解决方案1】:

在您的 .htaccess 文件中尝试以下操作

Options +FollowSymLinks
Options +Indexes
RewriteEngine On
RewriteBase /

#if an html version of this file exists
RewriteCond %{REQUEST_FILENAME}\.html -f [NC]
#then server it
RewriteRule . %{REQUEST_FILENAME}.html [NC,L]

【讨论】:

    猜你喜欢
    • 2010-12-04
    • 1970-01-01
    • 2010-12-15
    • 2017-12-07
    • 2015-02-05
    • 2013-06-12
    • 2012-04-17
    • 1970-01-01
    • 2011-07-28
    相关资源
    最近更新 更多