.htaccess 在 firefox 中检查 index.php 时产生一个 pre 标签

.htaccess produces a pre tag when inspecting the index.php in firefox

构建一个简约的 MVC,我需要一个 (.htaccess) 用于路由目的。我正在使用 apache 和虚拟端口。

index.php 是可见的,但它是一个预标记(不是 html 源代码的一部分)及其空白使页面向下移动,就好像顶部有 250 像素的边距一样。

出于某种原因,(.htaccess) 的使用将 html 代码包装在一个 pre 标记中,结果是头部内容移动到正文区域并在 [=48= 的每一行之间添加空格] 标签。

观察:

删除 (.htaccess) 会使 index.php 的结果恢复正常,并且浏览器不可见预标记(查看页面源代码),页面从浏览器顶部开始应该表现得很好。

我的index.php

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <link rel="stylesheet" href="application/content/css/main.css">
</head>
<body>

  <div class="wrapper">
    <div class="top_banner">tb</div>
    <div class="content">c</div>
    <div class="navigation">n</div>
    <div class="bottom_bar">bb</div>
  </div>

</body>
</html>

我的 .htaccess 文件

RewriteEngine On
RewriteRule \.(css|js|png|jpg|gif)$ - [L]
RewriteRule ^([^/]+)/? index.php?url= [L,QSA]
DirectoryIndex index.php

# Attempts to solve the problem with pre-tag.
#AddDefaultCharset UTF-8
#AddType text/html;charset=utf-8 html
#AddType text/plain;charset=iso-8859-1 txt
#AddType text/plain;charset=utf-8 text

我的apache文件(000-default-conf):

<VirtualHost *:100>
        DocumentRoot /var/www/mvc
</VirtualHost>

<Directory /var/www/mvc/versions/>
        Options Indexes FollowSymLinks
        AllowOverride All
</Directory>

浏览器中的结果html(查看页面源):

<pre>

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <link rel="stylesheet" href="application/content/css/main.css">
</head>
<body>

  <div class="wrapper">
    <div class="top_banner">tb</div>
    <div class="content">c</div>
    <div class="navigation">n</div>
    <div class="bottom_bar">bb</div>
  </div>

</body>
</html>

firefox检查器HTML代码

<html lang="en"><head></head><body><pre>



  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <link rel="stylesheet" href="application/content/css/main.css">



  <div class="wrapper">
    <div class="top_banner">tb</div>
    <div class="content">c</div>
    <div class="navigation">n</div>
    <div class="bottom_bar">bb</div>
  </div>



</pre></body></html>

在 RewriteRule 替换路径是相对的,所以 apache 尝试猜测,根据 Apache 文档:

mod_rewrite tries to guess whether you have specified a file-system path or a URL-path by checking to see if the first segment of the path exists at the root of the file-system.

你应该阅读 rewriteRule description 可能你在某处有一个文件添加了 pre 标签。