apache2 RewriteRule无法正常工作(id = $ id)

时间:2014-01-15 15:39:47

标签: php .htaccess apache2

我想将我的nieuws.php?id = $ id重定向到/nieuws/.html

这是我用于测试的nieuws.php脚本:

<?php 
if (isset($_GET["id"])) {
    $id = $_GET["id"];
    echo "Your ID: $id";
    exit();
} else {
    echo "No ID";
    exit();
}
?>

为此,我在.htaccess中有以下脚本。

Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteRule ^nieuws/([^/]*)\.html$ /nieuws.php?id=$1 [L]

当我打开http://localhost/nieuws/2.html时,我会无ID

但是,当我将规则更改为: RewriteRule ^nieuws([^/]*)\.html$ /nieuws.php?id=$1 [L](没有“子目录”)并打开http://localhost/nieuws2.html它有效,我得到您的ID:2

我知道如何添加“子域名”吗?

日Thnx!

1 个答案:

答案 0 :(得分:0)

您很可能已启用MultiViews

.htaccess

的顶部使用此行将其关闭
Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /

RewriteRule ^nieuws/([^.]+)\.html$ /nieuws.php?id=$1 [L,QSA]
相关问题