dsy6639 2016-02-08 18:16
浏览 50
已采纳

如何阻止我的index.php为每个用户运行两次

We've got a webapp where the initial html is served up using apache and php.

I recently noticed that index.php was being run twice for every request. This seems to be caused / effected by the rewrite rules in our .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]

The final rule is moving a parameter from the url path to the query string. i.e.

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

becomes

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

If I go directly to the query string version then index.php is only run once. However if use a url that will be redirected, then index.php is run twice (I'm checking by adding error_log('end of index.php') to the file).

So for example going to http://ourdomain.com/hotels/paris hits the file twice where as http://ourdomain.com?d=paris only hits it once.

I've seen this question and had a look at the blog mentioned, and I can't find any empty string url's (I've tried using yslow for this process).

Can anybody tell me why this is happening? or how I fix it?

EDIT

It looks like it's a javascript error I'm getting http requests like "GET /hotels/undefined HTTP/1.1" in the access log.

  • 写回答

1条回答 默认 最新

  • dongshao4207 2016-02-08 18:46
    关注

    Try last rule as:

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

    Or catch the erroneous requests with

    RewriteRule ^hotels/((?!undefined)[^/]+)/?$ index.php?d=$1 [NC,QSA,L]
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题