0

我只有一个 index.php 文件,它使用以下方法生成其他页面:

RewriteRule ^page 1.php$ index.php?cat=a [NC]
RewriteRule ^page 2.php$ index.php?cat=b [NC]

我正在尝试使用以下代码来更改页面的标题,但它仅适用于 index.php。

<?php
$page = $_SERVER['PHP_SELF'];
if(isset($page)) {
switch($page) {
case "/index.php":
$title = "this is homepage";
break;
case "/page 1.php":
$title = "products";
break;
case "/page 2.php":
$title = "services";
break;
}
}else{
$title = "default title";
}

print "<title>$title</title>";
?>
4

2 回答 2

1

验证我不确定它们在 url 中允许的空格

看看文档:

http://php.net/manual/en/reserved.variables.server.php

尝试这个 :

<?php
$page = $_GET['cat'];
if(isset($page)) {
switch($page) {
case "index":
$title = "this is homepage";
break;
case "a":
$title = "products";
break;
case "b":
$title = "services";
break;
}
}else{
$title = "default title";
}

print "<title>$title</title>";
?>
于 2013-07-30T11:06:28.643 回答
0

在重写规则中使用 \s 而不是空格:

RewriteRule ^page\s1.php$ index.php?cat=a [NC]
RewriteRule ^page\s2.php$ index.php?cat=b [NC]
于 2013-07-30T11:11:35.243 回答