我已经在本地机器上设置了XAMPP。我开始设置MVC,并注意到$_GET将我的本地目录结构一直返回到驱动器号。但是我想返回URL结构
我已尽力提供所有可能的相关信息。
- Windows 7 Professional SP1 64位
- XAMPP 1.8.1
[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>
Web目录结构 [E:'xampp'htdocs'home]
home
index.php
private
controllers
public
graphics
HTML5_Logo_512.png
首页[E: ' xampp '根' ' index . php | http://www.getspark.com/]
<?php
$url = $_GET['url'];
echo $url . '<br />';
?>
<img src="/public/graphics/HTML5_Logo_512.png" />
如果我使用以下URL:
http://www.getspark.com/foobar
我得到这样的输出:
E:/xampp/htdocs/home/foobar
还有图片
但是我想要这样的输出:
foobar
所有相对(和绝对)引用都可以正常工作(对于图像,php文件,js文件等)
使用$_SERVER['REQUEST_URI']被认为是更好的做法,它返回请求中域名之后的所有内容(根据apache/lighty,在重写之前)-在您的情况下是"/foobar"。