我有使用$ _SERVER ['REQUEST_URI']的PHP應用程序。如果我使用Apache Web服務器,我的應用程序工作正常。如果我使用Microsoft IIS Web服務器應用程序不工作,因爲$ _SERVER ['REQUEST_URI']爲空。我發現$ _SERVER ['REDIRECT_URL']可用於Microsoft IIS。如何在IIS中使用REQUEST_URI而不是REDIRECT_URL來獲得相同的功能?
我的問題是如何使用$ _ SERVER的代替$ _ SERVER [ 'REQUEST_URI'] [ 'REDIRECT_URL']使用Microsoft IIS Web服務器來獲得相同的功能?
我不能簡單地用REDIRECT_URL替換REQUEST_URI,因爲它不包含查詢字符串,我需要爲我的PHP應用程序。
我的PHP代碼:
function filterAppUrl($url)
{
$url = htmlspecialchars($url);
$url = str_replace('"', '', $url);
$url = str_replace("'", '', $url);
return $url;
}
function setAppURL()
{
$url = $this->filterAppUrl($_SERVER['REDIRECT_URL']);
$url = substr($url, 1, strlen($url));
$this->full_url = $url;
$this->url = explode('/', $url);
}
我的.htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
我對IIS
的Web.config<?xml version="1.0"?>
<configuration>
<system.webServer>
<defaultDocument>
<files>
<remove value="index.php" />
<add value="index.php" />
</files>
</defaultDocument>
<rewrite>
<rules>
<rule name="Main Rule" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="index.php" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
不,它不工作,因爲返回值不同於REDIRECT_URL和REQUEST_URI。我還用index.php重定向。我使用我的.htaccess和Web.config更新了這個問題,以便明確問題。 –
你在說什麼? REDIRECT_URL和REQUEST_URI都包含值,但您只能通過檢查腳本運行的服務器來確定哪一個是正確的? –
我讀過這個:「請注意,REDIRECT_URL只包含URI路徑。」 http://stackoverflow.com/questions/6483912/php-serverredirect-url-vs-serverrequest-uri我試過你的代碼,但應用程序沒有像Apache服務器一樣工作。 –