如何停止我的索引.php为每个用户运行两次


How do I stop my index.php being run twice for every user

我们有一个webapp,其中使用apache和php提供初始html。

我最近注意到 index.php 为每个请求运行两次。这似乎是由我们的 .htaccess 中的重写规则引起/影响的 -

RewriteCond %{HTTP_HOST} ^(www'.|hotels'.)ourdomain'.com$ [NC,OR]
RewriteCond %{SERVER_NAME} ^(www'.|hotels'.)ourdomain'.com$ [NC]
RewriteRule (.*) http://ourdomain.com/$1 [R=301]
RewriteRule ^hotels/([^/]+)/?'??(.*)$ ?d=$1&$2 [QSA]

最后的规则是将参数从 url 路径移动到查询字符串。

http://ourdomain.com/hotels/vegas?someParam=1

成为

http://ourdomain.com?d=vegas&someParam=1

如果我直接转到查询字符串版本,则索引.php只运行一次。但是,如果使用将被重定向的 url,则 index.php 将运行两次(我正在通过将 error_log('end of index.php') 添加到文件中进行检查(。

因此,例如,转到http://ourdomain.com/hotels/paris会命中文件两次,而http://ourdomain.com?d=paris只命中一次。

我已经看到了这个问题并查看了提到的博客,但我找不到任何空字符串 url(我尝试使用yslow进行此过程(。

谁能告诉我为什么会这样?或者我如何解决它?

编辑

看起来这是一个javascript错误,我收到访问日志中"GET /hotels/undefined HTTP/1.1"这样的http请求。

尝试最后一个规则为:

RewriteRule ^hotels/([^/]+)/?$ index.php?d=$1 [NC,QSA,L]

或者使用

RewriteRule ^hotels/((?!undefined)[^/]+)/?$ index.php?d=$1 [NC,QSA,L]