我想改变网址,如下所示:如何使用PHP/.htaccess更改URL查询字符串?
http://localhost/register/profile.php?user_id=23
到:
http://localhost/register/username
我想改变网址,如下所示:如何使用PHP/.htaccess更改URL查询字符串?
http://localhost/register/profile.php?user_id=23
到:
http://localhost/register/username
考虑ID 23和用户名 “富” 的用户。最简单的就是重写/注册/ 23 /富到/register/profile.php?user_id=23这样:
RewriteEngine on
RewriteRule ^/register/([0-9]+)/([^/]+)/$ /register/profile.php?user_id=$1 [L,R]
但如果你可以改变profile.php依靠$_GET['username']
而非$_GET['user_id']
,您可以将/register/foo改写为/register/profile.php?username=foo。使用此规则:
RewriteEngine on
RewriteRule ^/register/([^/]+)/$ /register/profile.php?username=$1 [L,R]
您必须启用mod_rewrite的。 互联网充满了示例教程。