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 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥15 (关键词-阻抗匹配,HFSS,RFID标签天线)
  • ¥15 机器人轨迹规划相关问题
  • ¥15 word样式右侧翻页键消失