繁体   English   中英

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

[英]apache2 RewriteRule not working correctly (id=$id)

我想将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

任何想法我可以添加一个“子域”吗?

谢谢!

您很可能已启用MultiViews

使用.htaccess顶部的此行将其关闭:

Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM