2013-04-20 64 views
0

我在本地機器上設置了XAMPP。我開始設置我的MVC,並注意到$ _GET將我的本地目錄結構一直返回到驅動器盤符。但是我想返回URL結構。

我試圖提供所有可能的相關信息。

環境

主機 [C:\ Windows \ System32下\驅動程序\等\主機]

127.0.0.1  www.getspark.com 

的httpd.conf [E:\ XAMPP \ apache的\的conf \ httpd.conf文件]

DocumentRoot "E:/xampp/htdocs/home" 

<VirtualHost *:80> 
    DocumentRoot /xampp/htdocs/home 
    ServerName getspark 
</VirtualHost> 
<Directory "E:/xampp/htdocs/home/private"> 
    Order deny,allow 
    Deny from all 
</Directory> 
<Directory /> 
    RewriteEngine On 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteCond %{REQUEST_FILENAME} !-l 
    RewriteRule ^(.+)$ /index.php?url=$1 [L,QSA] 
</Directory> 

網站目錄結構 [E:\ XAMPP \ htdocs中\家居】

home 
    index.php 
    private 
     controllers 
    public 
     graphics 
      HTML5_Logo_512.png 

主頁 [E:\ xampp \ htdocs \ home \ index.php | http://www.getspark.com/]

<?php 
$url = $_GET['url']; 
echo $url . '<br />'; 
?> 
<img src="/public/graphics/HTML5_Logo_512.png" /> 

如果我使用以下網址:

http://www.getspark.com/foobar 

我得到這樣的輸出:

E:/xampp/htdocs/home/foobar 

除了圖像。

但我想這樣的輸出:

foobar 

所有相對(絕對)引用正常工作(對於圖像,PHP文件,js文件等)。

回答

0

使用$ _SERVER ['REQUEST_URI']被認爲是更好的做法,它返回域中的所有請求(根據apache/lighty,在重寫之前) - 「/ foobar」。