XAMPP为$_SERVER[“REQUEST_URI”]返回比web服务器更长的URL


XAMPP returning longer URL for $_SERVER["REQUEST_URI"] than web server

我正在使用此代码获取URL 的一部分

$artist = substr($_SERVER["REQUEST_URI"], 9, -1);

这在我的正常网站上运行良好,只返回URL的最后一部分;然而,当在我的本地机器上使用XAMPP时,它会返回整个更长的URL。差异有原因吗?有没有办法修改它,使它们返回相同的结果?

在我的网站上,如果URL是这样的,它会返回"Mercury"http://www.saint57records.com/artists/Mercury/使用以下htaccess

RewriteCond %{REQUEST_URI} !^/artists/index.php.*
RewriteRule    ^artists/(.+)$    artists/index.php?$1 [L]

在XAMPP上,它返回"ecords/artists/index.php?Mercury",URL为http://localhost/saint57records/artists/index.php?Mercury/,这个htaccess不适用于XAMPP,所以我必须写出

localhost != saint57records.com

由于.htaccess mod_rewrite规则不会重写url本地examplep安装上的$_SERVER["REQUEST_URI"] = "/saint57records/artists/index.php?Mercury/",因此substr失败。

检查您的xampp安装中是否启用了apachemod_rewrite。