Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如果我的网站是www.example.com并且用户输入www.example.com/robert我想在www.example.com/users?user=robert. 基本上我想为每个用户创建一个个人资料页面,但我希望它可以通过在域之后输入用户名作为目录来访问。
www.example.com
www.example.com/robert
www.example.com/users?user=robert
如何使用 .htaccess 执行此操作?
通过启用 mod_rewrite 和 .htaccess httpd.conf,然后将此代码放在您.htaccess的DOCUMENT_ROOT目录下:
httpd.conf
.htaccess
DOCUMENT_ROOT
Options +FollowSymLinks -MultiViews # Turn mod_rewrite on RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.+?)/?$ /users.php?user=$1 [L,QSA]