重写url以删除问号并在htaccess中添加斜杠 [英] Rewrite url to remove question mark and add slashes in htaccess
问题描述
我花了几个小时来尝试实现我认为很简单的目标.我有http://localhost/testing_url_document/second.php?id=2
,想将其设为http://localhost/testing_url_document/second/id/2
.我已经实现了删除php扩展名的功能,但仍然无法重写站点页面.在htacces中,我按照以下步骤操作.
I've spent a couple of hours trying to achieve something I thought was easy. I have http://localhost/testing_url_document/second.php?id=2
and want to turn it http://localhost/testing_url_document/second/id/2
. I have achieved to remove the php extension but stucked into the rewriting the site page . In the htacces i have followed the following procedure.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
这是我的索引页
Index.php
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>
Second.php
Second.php
<?php
echo $_GET['id'];
?>
second.php应该获得值2
The second.php should gets the value 2
预先感谢您的帮助.
推荐答案
在/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]
这篇关于重写url以删除问号并在htaccess中添加斜杠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!