[英]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
如果我直接转到查询字符串版本,那么index.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]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.