重写url以删除问号并在htaccess中添加斜杠 [英] Rewrite url to remove question mark and add slashes in htaccess

查看:69
本文介绍了重写url以删除问号并在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆