Php 如何在Yii中创建自定义url
可能重复:Php 如何在Yii中创建自定义url,php,yii,url-mapping,Php,Yii,Url Mapping,可能重复: 如何管理用户配置文件的自定义url,如 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文件
如何管理用户配置文件的自定义url,如
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',
),
),
urlManager'=>数组(
“urlFormat'=>“路径”,
'showScriptName'=>false,
'规则'=>数组(
“/”=>“/视图”,
'//'=>'/',
'/'=>'/',
'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]
并且确保你必须在页面中包含
名称
,我不想在查询字符串中发送名称,我想在查询字符串中发送用户id我该怎么做?john id是31,那么如何在htaccess或config/main.php中动态获得31呢?我认为这是不可能的,你不能在htaccess文件中执行数据库操作,我认为你也不能在main.php配置中编写这样的规则……是的,非常感谢!很高兴知道这一点,你能分享你使用的方法吗?首先,检查一下yii社区提供了什么;我相信您会发现有一个url友好的扩展/插件/模块