【问题标题】:how to hide GET variable from url如何从 url 隐藏 GET 变量
【发布时间】:2013-08-19 15:13:46
【问题描述】:

我一直被这个 <a href="profile.php?u=<?php echo $uiname ?>"/> 所困扰 ,我试图隐藏$_GET 变量但没有成功。 我想要实现的是 www.mywebsitename.com/profile/name 或 www.mywebsite.com/name 而不是

profile.php?u=name

有可能吗?

【问题讨论】:

标签: php .htaccess url


【解决方案1】:

对于您的网址:http://localhost/ifinal/profile/myname

你可以在htaccess中使用like:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /ifinal/

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^profile/(.*) profile.php?u=$1
</IfModule>

如果您的网站不是下文件夹,请使用 RewriteBase /

并使用 HTML

<a href="profile/<?php echo $uiname; ?>">
   <?php echo $uiname; ?>
</a>

【讨论】:

  • @user2660611 更新了代码。复制并粘贴到 root .htaccess 并让我知道您是否遇到任何错误。希望它有效
  • 你得到了什么?你的网址到底是什么?根目录还是子文件夹?
  • 您的站点在子文件夹下?如果你输入www.mywebsitename.com/profile/name 你会看到什么?
  • 它对我有用。更新了代码。请再试一次。注意RewriteBase
  • @user2660611 你做错了什么。这个对我有用。您必须定义RewriteBase /ifinal/ 并输入http://localhost/ifinal/profile/myname。更新代码
猜你喜欢
  • 2011-04-07
  • 2016-12-02
  • 1970-01-01
  • 2014-06-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-08-23
相关资源
最近更新 更多