可能的重复:
如何为我的网页制作像 Facebook 一样的用户个人资料链接 https://stackoverflow.com/questions/13117488/how-to-make-user-profile-link-like-facebook-for-my-web-page
我如何管理用户个人资料的自定义网址,例如
www.exampl.com/brito insted of www.exampl.com/user/profile/id/22
www.exampl.com/jhon insted of www.exampl.com/user/profile/id/31
www.exampl.com/piter insted of www.exampl.com/user/profile/id/66
我已经在 config/main.php 文件中完成了以下代码,现在它仅适用于这 3 个静态用户。我如何为所有 1000 个用户动态更改它?
urlManager'=>array(
'urlFormat'=>'path',
'showScriptName'=>false,
'rules'=>array(
'<controller:\w+>/<id:\d+>'=>'<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
'brito'=>'user/profile/id/22',
'john'=>'user/profile/id/31',
'piter'=>'user/profile/id/66',
),
),
请任何人帮助我。
使用 htaccess
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
# If the request is for a valid directory
RewriteCond %{REQUEST_FILENAME} -d
# If the request is for a valid file
RewriteCond %{REQUEST_FILENAME} -f
# If the request is for a valid link
RewriteCond %{REQUEST_FILENAME} -l
# do not do anything
RewriteRule ^ - [L]
# forward /blog/foo to blog.php/foo
RewriteRule ^blog/(.+)$ blog.php/$1 [L,NC]
# forward /john to user/profile/?name=john
RewriteRule ^((?!blog/).+)$ user/profile/?name=$1 [L,QSA,NC]
并确保你必须包括name
在页面中
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)