douxian3170 2016-06-28 13:02
浏览 60
已采纳

用node.js执行php 使用.htaccess重定向

I've got a Node.js-Server:

app.use(express.static(__dirname + '/public'));

The Problem: When I want to execute a php-file like this:

var xhttp= new XMLHttpRequest();

xhttp.onreadystatechange = function(){
    if(xhttp.readyState==4 && xhttp.status==200){

        var text = xhttp.responseText;
        console.log(text);

    }
}

xhttp.open("GET","php/gethighscore.php",true);
xhttp.send();

I'll get the code from the php-file as response:

<?php
echo "test";
?>

I know that Node.js send me the static file but I don't know how to avoid that.

I already tried with the .htaccess-file:

RewriteEngine On

#Redirecting the php
RewriteCond %{REQUEST_FILENAME}       !-f
RewriteCond %{REQUEST_FILENAME}       !-d
RewriteRule ^(.php)$ my-webhost.com/public/php/ [L]

#Redirecting for node
RewriteCond %{REQUEST_FILENAME}       !-f
RewriteCond %{REQUEST_FILENAME}       !-d
RewriteRule ^(.*)$ http://localhost:64332/$1 [P]

But it doesn't work.

When I go to my-webhost.com/public/php/gethighscore.php I get the executed php-script. When I go to my-webhost.com/public/ I'll can use my application without node.js and the php-script is working fine.

I hope you can help me. :)

  • 写回答

2条回答 默认 最新

  • dongshuzhuo5659 2016-06-28 13:10
    关注

    Ok, I've already got it. I just changed

    xhttp.open("GET","php/gethighscore.php",true);
    

    to

    xhttp.open("GET","public/php/gethighscore.php",true);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 有没有整苹果智能分拣线上图像数据
  • ¥20 有没有人会这个东西的
  • ¥15 cfx考虑调整“enforce system memory limit”参数的设置
  • ¥30 航迹分离,航迹增强,误差分析
  • ¥15 Chrome Manifest扩展引用Ajax-hook库拦截请求失败
  • ¥15 用Ros中的Topic通讯方式控制小乌龟的速度,走矩形;编写订阅器代码
  • ¥15 LLM accuracy检测
  • ¥15 pycharm添加远程解释器报错
  • ¥15 如何让子窗口鼠标滚动独立,不要传递消息给主窗口
  • ¥15 如何能达到用ping0.cc检测成这样?如图