【问题标题】:apache2 RewriteRule not working correctly (id=$id)apache2 RewriteRule 无法正常工作(id=$id)
【发布时间】:2014-01-16 00:14:31
【问题描述】:

我想将我的 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 时,我得到 No ID

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

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

谢谢!

【问题讨论】:

    标签: php .htaccess apache2


    【解决方案1】:

    您很可能启用了MultiViews

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

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

    【讨论】:

    • 在您的 DocumentRoot/.htacces 中尝试上面输入的代码
    猜你喜欢
    • 2016-09-17
    • 1970-01-01
    • 2013-07-29
    • 2014-02-13
    • 2023-01-14
    • 1970-01-01
    • 1970-01-01
    • 2011-12-18
    • 2012-02-19
    相关资源
    最近更新 更多