【发布时间】:2013-07-22 15:42:35
【问题描述】:
我有一个必须更改位置的位置菜单,好在每个城市都存在每个 url,每个城市都是一个子域
city1.domain.com.uk/index.php?page=category/238/12
city2.domain.com.uk/index.php?page=category/238/12
我正在尝试这个。我试图打破 URL 以删除子域,所以我可以为菜单中的每个项目替换它
我想得到index.php?page=category/238/12
<?PHP
$protocol = strpos(strtolower($_SERVER['SERVER_PROTOCOL']),'https')=== FALSE ? 'http' : 'https';
$host = $_SERVER['HTTP_HOST'];
$script = $_SERVER['SCRIPT_NAME'];
$params = $_SERVER['QUERY_STRING'];
$url = $protocol . '://' . $host . $script . '?' . $params;
// break it up using the "."
$urlb = explode('.',$url);
// get the domain
$dns = $urlb[count($urlb)-1];
// get the extension
$ext = $urlb[count($urlb)+0];
//put it back together
$fullDomain = $dns.'.'.$ext;
echo $fullDomain;
?>
但我知道php?page=category/238/12
我还没有想到解决我将面临的问题..
如果我正在查看产品,则 url 会更改为类似
city2.domain.com.uk/index.php?page=item/preview/25
但是,不是每个城市都有产品,所以我的用户会得到一个 404。
=(
如何在此过程中设置条件,所以如果 page=item/preview/25 我确实将其替换为
page=index/index
【问题讨论】:
-
不要那样做。使用php.net/parse_url
-
我在使用解析,我可以删除www。 (基于此stackoverflow.com/questions/6667086/…)(¿我如何更改任何子域的代码中的 www. 而不仅仅是 www.?