我花了几个小时试图实现我认为很容易的事情。我有 http://localhost/testing_url_document/second.php?id=2
,想将其转换为 http://localhost/testing_url_document/second/id/2
。我已经成功去掉了php扩展名,但卡在了重写网站页面上。在htaccess文件中,我按照以下步骤进行操作。
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
这是我的首页
索引.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>
Second.php
<?php
echo $_GET['id'];
?>
第二个php应该获取值2。
提前感谢您的帮助。
http://localhost/testing_url_document/second.php/id/2
时会发生什么? - anubhava/testing_url_document/.htaccess
文件吗? - anubhava