如何使用php将用户名显示为url的一部分

如何使用php将用户名显示为url的一部分,php,Php,如何在URL示例中传递用户名以这种格式显示。example.com/username而不是=username 任何帮助都会有很大的帮助,谢谢以下是您的写作方法: RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php?user=$1 [NC] 如果希望/category/username模拟/category.php

如何在URL示例中传递用户名以这种格式显示。example.com/username而不是=username
任何帮助都会有很大的帮助,谢谢

以下是您的写作方法:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?user=$1 [NC]
如果希望/category/username模拟/category.php?user=username,则:


您应该在htaccess中查看它的正确格式并添加答案。您已将.htaccess放入您希望url缩短的文件夹中。我正在使用wamp使用localhost server进行测试,但在测试运行时,我收到此错误消息internal server errorthis I what I what I what I this I this I this I this I this I this I this I this I this in in apache error log bad argument line RewriteCond%{REQUEST_FILENAME}-fIt在我这边非常好用。我似乎无法重现这个问题。它现在起作用了,但我得到的是localhost/mysite/category.php?user=username,而不是localhost/mysite/category/username。我更新了我的帖子,介绍了如何做到这一点。请将投票/标记作为解决方案,这很有帮助。
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^category/(.*)$ category.php?user=$1 [NC]