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);
    
    打赏 评论
  • doufu6504 2016-06-28 13:06

    Try this one replace your my_project name to your project name

    RewriteEngine on
    RewriteCond $1 !^(index\.php|images|asset|js|robots\.txt)
    RewriteRule ^(.*)$ /my_project /index.php/$1 [L]
    
    打赏 评论

相关推荐 更多相似问题