如何更改使用PHP /的.​​htaccess URL查询字符串? [英] How to change URL query string with PHP/.htaccess?

查看:186
本文介绍了如何更改使用PHP /的.​​htaccess URL查询字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想改变URL中包含:

 的http://localhost/register/profile.php USER_ID = 23
 

 的http://本地主机/寄存器/用户名
 

解决方案

考虑ID 23和用户名的用户的的。最简单的是重写 /注册/ 23 /富到/register/profile.php?user_id=23 作为这样的:

  RewriteEngine叙述上
重写规则^ /注册/([0-9] +)/([^ /] +)/ $ /register/profile.php?user_id=$1 [L,R]
 

但是,如果你可以改变profile.php依靠 $ _ GET ['用户名'] ,而不是 $ _ GET ['USER_ID] ,你可以重写 /注册/富到/register/profile.php?username=foo 。使用这条规则:

  RewriteEngine叙述上
重写规则^ /注册/([^ /] +)/ $ /register/profile.php?username=$1 [L,R]
 

I want to change URL like below:

http://localhost/register/profile.php?user_id=23

to:

http://localhost/register/username

解决方案

Consider a user of id 23 and username "foo". The easiest is to rewrite /register/23/foo to /register/profile.php?user_id=23 as such:

RewriteEngine on 
RewriteRule ^/register/([0-9]+)/([^/]+)/$ /register/profile.php?user_id=$1 [L,R]

But if you can change profile.php to rely on $_GET['username'] rather than $_GET['user_id'], you can rewrite /register/foo to /register/profile.php?username=foo. Use this rule:

RewriteEngine on 
RewriteRule ^/register/([^/]+)/$ /register/profile.php?username=$1 [L,R]

这篇关于如何更改使用PHP /的.​​htaccess URL查询字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆