【问题标题】:Redirect all requests to main page using htaccess (hide index.html in URL)使用 htaccess 将所有请求重定向到主页(在 URL 中隐藏 index.html)
【发布时间】:2014-10-06 19:05:33
【问题描述】:

我想将所有请求重定向到主页 (index.html)。状态栏中的 URL 不应显示 index.html。此时我正在使用以下代码重定向到 index.html 并在 URL 中显示它:

RewriteEngine on RewriteCond %{REQUEST_URI} !^/index.html$ RewriteCond %{REQUEST_URI} !.(gif|jpeg|png|css|js)$ RewriteRule .* /index.html [L,R=302]

我应该进行哪些更改才能使其按预期工作?谢谢!

【问题讨论】:

  • 应该在没有 R=302 标志的情况下工作。仅使用[L] 标志(内部重写)
  • 它不起作用。实际上它根本没有重定向。
  • 比你在别处犯了错误。删除 R=302(和它前面的逗号),这会导致重定向标头发送到浏览器。如果一切正常 - 如果没有该标志,它会更好地工作。

标签: html .htaccess mod-rewrite redirect


【解决方案1】:

试试:

RewriteEngine on 
RewriteCond %{REQUEST_URI} !^/(index.html)?$ 
RewriteCond %{REQUEST_URI} !.(gif|jpeg|png|css|js)$ 
RewriteRule .* / [L,R=302]

【讨论】:

    【解决方案2】:

    如果它按预期工作,除了浏览器的外部重定向,那么您只需删除 R=302 标志,它告诉服务器发送 302 标头。

    RewriteEngine on
    RewriteCond %{REQUEST_URI} !^/index.html$
    RewriteCond %{REQUEST_URI} !.(gif|jpeg|png|css|js)$
    RewriteRule .* /index.html [L]
    

    还要检查 DirectoryIndex 指令,默认显示 index.html(如果已更改)

    【讨论】:

      猜你喜欢
      • 2013-02-15
      • 1970-01-01
      • 2021-05-25
      • 2012-11-09
      • 2015-04-10
      • 2015-08-21
      • 2012-12-10
      • 2015-05-25
      • 1970-01-01
      相关资源
      最近更新 更多