隐藏GET请求中的网址参数

猎人91151

我想使用来从$_GET请求中隐藏一些url参数.htaccess我尝试了不同的方法,当然也可以从此链接中进行尝试:如何隐藏使用.htaccess在url中传递的参数

但这对我失败了:

错误图片-隐藏的ID

我的.htaccess代码:

RewriteEngine On
RewriteRule ^([0-9a-zA-Z]+)/([0-9]+)/?$ $1.php?id=$2
RewriteRule ^([0-9a-zA-Z]+)/?$ /$1.php

但这仅在id添加时有效:

有ID作品

我想隐藏id并显示为:

localhost/get_test.net/test/4

更新:因此,它适用于以下代码:

RewriteBase /
RewriteEngine On
RewriteRule ([^/\.]+)/?$ test.php?id=$1 [L]

现在,我需要更改test.php为任何链接并解决index.php页面问题,因为找不到该链接:

找不到索引页

有任何想法吗?谢谢。

怀特先生

如果您的文件结构是这样的(来自屏幕截图):

/get_test.net
    .htaccess
    test.php
    index.php

然后重写/get_test.net/<file>/<id>/get_test.net/<file>.php?id=<id>,其中<id>是数字,并且/<id>是可选的,那么您需要执行以下操作:

# Prevent conflict with mod_negotiation
Options -MultiViews

RewriteEngine On

# Do NOT set RewriteBase (or set it to the subdirectory)
#RewriteBase /get_test.net

# Rewrite /<file>/<id> to <file>.php?id=<id>
RewriteRule ^([^/.]+)(?:/(\d+))?$ $1.php?id=$2 [L]

在正则表达式字符类中使用时,无需转义文字点。

更新:上面还处理/<id>了URL省略尾部的情况例如。/index被重写/index.php?id=(不是空的URL参数)。还请注意,如果提供了末尾斜杠,则ID也必须包含1个或多个数字。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章