本文介绍了重写url以删除问号并在htaccess中添加斜杠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我花了几个小时来尝试实现我认为很简单的目标.我有localhost/testing_url_document/second.php?id=2,想将其设为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 localhost/testing_url_document/second.php?id=2 and want to turn it 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中添加斜杠
发布评论