簡體   English   中英

使用node.js執行php | 使用.htaccess重定向

[英]Execute php with node.js | Redirecting with .htaccess

我有一個Node.js服務器:

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

問題:當我想執行這樣的php文件時:

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();

我將從php文件中獲取代碼作為響應:

<?php
echo "test";
?>

我知道Node.js向我發送了靜態文件,但我不知道如何避免這種情況。

我已經嘗試過.htaccess文件:

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]

但這是行不通的。

當我訪問my-webhost.com/public/php/gethighscore.php我得到了已執行的php腳本。 當我訪問my-webhost.com/public/可以使用沒有node.js的應用程序,並且php腳本可以正常工作。

我希望你能幫助我。 :)

試試這個,將您的my_project名稱替換為您的項目名稱

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

好的,我已經知道了。 我剛換

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

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM