【问题标题】:How to show user information when user name is at the end of link当用户名在链接末尾时如何显示用户信息
【发布时间】:2019-01-26 16:24:58
【问题描述】:

我有一个网站,说它

http://www.mywebsite.com

现在如果我执行类似的操作,我可以显示用户信息

http://mywebsite.com/user.php?name=John

我使用php查询数据库以生成用户信息到一个html页面

但是我该怎么做呢

http://www.mywbsite.com/john

我是否为我拥有的每个用户创建一个页面?或者有没有更好的方法

【问题讨论】:

标签: php html web


【解决方案1】:

这是从 URL 中隐藏 user.php?name= 的基本规则。把它放在你的根 .htaccess 文件中。

mod_rewrite 必须使用 PHP 启用,这将适用于高于 5.2.6 的 PHP 版本。

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ user.php?name=$1 [L]

【讨论】:

    【解决方案2】:

    你可以像这样使用 .htaccess

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ user.php?name=$1 [QSA]
    

    然后获取用户

    <?php 
     $user = $_GET['name'];
    ?>
    

    【讨论】:

      猜你喜欢
      • 2018-02-17
      • 2021-09-10
      • 1970-01-01
      • 2016-05-13
      • 2012-08-29
      • 1970-01-01
      • 2015-07-25
      • 2021-02-28
      • 1970-01-01
      相关资源
      最近更新 更多