【问题标题】:Hide parameter (query string) in url (htaccess)在 url (htaccess) 中隐藏参数(查询字符串)
【发布时间】:2014-09-03 10:29:45
【问题描述】:

如何在 URL 中隐藏参数(query_string)但将它们发送到隐藏的页面,在地址栏中不可见 示例:

我有这个:

   http://localhost/project/company/redeem/category/Shirts/18?category_id=18

我想要:

   http://localhost/project/company/redeem/category/Shirts.html

但我想在 PHP $_GET['sent'] 中获取发送参数

我尝试重定向到没有参数的页面(没有 query_string)[R],然后给页面一些参数(静默)没有 [R] 重定向(不改变地址本身)

我尝试在 .htaccess 中以不同的标志和不同的方式使用 RewriteRule,但没有任何效果

请提出建议。

【问题讨论】:

标签: php .htaccess mod-rewrite laravel-4


【解决方案1】:

据我所知,您只能使用 RewriteEngine 隐藏参数键(在本例中为“category_id”):

RewriteEngine On

然后像这样使用 RewriteRule

RewriteRule ^project/company/redeem/category/Shirts/18/(regex of whatever you expect for your parameter)$ project/company/redeem/category/Shirts/18.php?category_id=$1

不确定前 18 个是巧合还是始终与 category_id 值相同。如果是你也可以使用

RewriteRule ^project/company/redeem/category/Shirts/(regex of whatever you expect for your parameter)$ project/company/redeem/category/Shirts.php?category_id=$1

如果您想使用 $_GET,则必须将参数写入 url somewhere。你只能尝试隐藏它。

例如,如果您知道每个类别的名称,则可以将其放入 url 而不是数字。假设 category_id 18 是“V-Neck Unisex-Shirts”,您可以使用类似的网址

http://localhost/project/company/redeem/category/Shirts/V-Uni

并告诉您的脚本使用类别“V-Uni”而不是“18”。
.htaccess:

RewriteRule ^project/company/redeem/category/Shirts/([a-zA-Z-]*)$ project/company/redeem/category/Shirts.php?category=$1

【讨论】:

    猜你喜欢
    • 2012-11-08
    • 1970-01-01
    • 2011-08-26
    • 2012-01-23
    • 2012-09-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多