php – 重写url以删除问号并在htaccess中添加斜杠
发布时间:2020-12-13 15:58:49 所属栏目:PHP教程 来源:网络整理
导读:我花了几个小时试图实现我认为很容易的事情.我有http://localhost/testing_url_document/second.php?id = 2并想把它变成http:// localhost / testing_url_document / second / id / 2.我已经实现了删除 PHP扩展,但坚持重写网站页面.在htacces中,我遵循以
我花了几个小时试图实现我认为很容易的事情.我有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] 这是我的索引页面 的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 <?php echo $_GET['id']; ?> second.php应该得到值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] (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |