0

我的 .htaccess 文件中有以下重写规则

<IfModule mod_rewrite.c>
RewriteEngine on

RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*)$ index.php?$1 [L,QSA]

</IfModule>

在 index.php 文件中,我通过 PHP 邮件功能向自己发送了一封电子邮件。

<?php
$body = "<html>";
$body .= "<body>";
$body .= $_SERVER['REMOTE_ADDR'];
$body .= "</body>";
$body .= "</html>";

$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
$headers .= 'From: XXX@domain.com' . "\r\n";

mail('XXX@mail.com', 'IP TEST', $body, $headers, "-fXXX@domain.com");
?>

当我在网络浏览器http://sub.domain.com中访问 URL 时,有两封电子邮件发送给我。

当我访问http://sub.domain.com/index.php时也是如此

当我在 .htaccess 文件中注释掉所有内容时,只发送一封电子邮件。

我不明白!

4

2 回答 2

0

规则中的语法错误:
来自:RewriteCond %{REQUEST_URI} !=/favicon.ico
需要:RewriteCond %{REQUEST_URI} !^/favicon.ico$

Network还要在选项卡中检查所有请求的文件中的萤火虫。它可以帮助调试。

于 2012-09-12T15:01:35.080 回答
0

如果这是您根目录下的默认文档,则 favicon 请求仍将发送至 index.php。它未能通过 RewriteCond 并成为标准请求。尝试为它返回 404。

RewriteEngine on

RewriteBase /

RewriteRule ^favicon.ico$ - [R=404,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1 [L,QSA]
于 2012-09-12T15:19:37.667 回答