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

编程入门 行业动态 更新时间:2024-10-14 22:16:16
本文介绍了重写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中添加斜杠

本文发布于:2023-11-01 13:15:15,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1549420.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:斜杠   并在   重写   问号   url

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!