重写url以删除问号并在htaccess中添加斜杠

Har*_*thi 5 php apache .htaccess mod-rewrite

我花了几个小时来尝试实现我认为很容易的目标。我有http://localhost/testing_url_document/second.php?id=2,想把它打开http://localhost/testing_url_document/second/id/2。我已经实现了删除php扩展名的功能,但是仍然无法重写站点页面。在htacces中,我遵循以下过程。

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
Run Code Online (Sandbox Code Playgroud)

这是我的索引页

Index.php

<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>
    <body>
        <?php
        // put your code here
        ?>
        <a href="second/id/2">click here</a>
    </body>
</html>
Run Code Online (Sandbox Code Playgroud)

Second.php

<?php 
 echo $_GET['id'];
?>
Run Code Online (Sandbox Code Playgroud)

second.php应该获取值2

在此先感谢您的帮助。

anu*_*ava 3

里面是这样的/testing_url_document/.htaccess

RewriteEngine On
RewriteBase /testing_url_document/

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^./]+)(/.*)?$ $1.php$2 [L]

RewriteRule ^([\w-]+(?:\.php)?)/([\w-]+)/([\w-]+)/?$ $1?$2=$3 [L,QSA,NC]
Run Code Online (Sandbox Code Playgroud)