我只有一个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>";
?>
答案 0 :(得分:1)
验证我不确定在网址中允许的空格
查看文档:
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>";
?>
答案 1 :(得分:0)
在重写规则中使用\ s而不是空格:
RewriteRule ^page\s1.php$ index.php?cat=a [NC]
RewriteRule ^page\s2.php$ index.php?cat=b [NC]