【问题标题】:Hide Get Parameter using .htaccess使用 .htaccess 隐藏获取参数
【发布时间】:2018-02-14 09:48:57
【问题描述】:

这是我的页面

xyz.com?show=page

在我的 index.php 中,代码会是这样的

<?php
echo $_GET['show']
?>

但我希望用户只输入xyz.com/page,它应该自动在网址中附加?show

我该怎么做?

我有 .htaccess 之类的

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

但它只删除页面的最后一部分,即 .php

我该怎么做

【问题讨论】:

    标签: php .htaccess url mod-rewrite friendly-url


    【解决方案1】:

    如果index.php 将处理您的所有请求,您需要重写它们index.php。您现在正在做的是将它们重写为当前请求并在末尾添加.php

    这应该做你想做的:

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^([^\.]+)$ /index.php?show=$1 [NC,L]
    

    【讨论】:

    • 但是如果我们在子文件夹中有文件就不行了?
    • 你必须用你想要的来更新问题。我只能猜测。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-10-09
    • 2018-12-08
    • 2013-01-03
    • 1970-01-01
    • 1970-01-01
    • 2020-04-03
    • 1970-01-01
    相关资源
    最近更新 更多