简体   繁体   English

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

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

I want to redirect my nieuws.php?id=$id to /nieuws/.html 我想将nieuws.php?id = $ id重定向到/nieuws/.html

This is my nieuws.php script for testing: 这是我的nieuws.php脚本进行测试:

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

For that i have the following script in .htaccess. 为此,我在.htaccess中有以下脚本。

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

When i open http://localhost/nieuws/2.html i get No ID 当我打开http://localhost/nieuws/2.html没有ID

But, when i change the rule to: RewriteRule ^nieuws([^/]*)\\.html$ /nieuws.php?id=$1 [L] (without the "subdirectory") and open http://localhost/nieuws2.html it works, i get Your ID: 2 但是,当我将规则更改为: RewriteRule ^nieuws([^/]*)\\.html$ /nieuws.php?id=$1 [L] (无“子目录”)并打开http://localhost/nieuws2.html它有效,我得到您的ID:2

Any idea how i can add a "subdomain"? 任何想法我可以添加一个“子域”吗?

Thnx! 谢谢!

Most likely you have MultiViews enabled. 您很可能已启用MultiViews

Turn it off using this line on top of your .htaccess : 使用.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