2

可能重复:
如何为我的网页制作像 facebook 这样的用户个人资料链接

我如何管理用户个人资料的自定义网址,例如

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',
                ),
            ),

请帮助我任何一个。

4

1 回答 1

0

使用 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在页面中包含

于 2012-10-29T11:57:31.437 回答