您好,欢迎访问一九零五行业门户网

php怎么设置url模式

php设置url模式的方法:1、通过“'url_case_insensitive'=>true”设置url是否区分大小写;2、通过“'url_html_suffix'=>'html|shtml|xml'”限制伪静态后缀;3、设置url路由。
本文操作环境:windows7系统、php7.1版、dell g3电脑。
php怎么设置url模式?
php对url设置
一、url规则
 1、默认是区分大小写的
 2、如果我们不想区分大小写可以改配置文件
'url_case_insensitive'=>true, //url不区分大小写
3、如果模块名为 usergroupaction
那么url找模块就必要要写成
http://localhost/thinkphp4/index.php/user_group/index
4、如果'url_case_insensitive'=>false
那么url也可以写为
http://localhost/thinkphp4/index.php/usergroup/index
二、url伪静态
'url_html_suffix'=>'html|shtml|xml',//限制伪静态的后缀
三、url路由
1、启动路由
要在配置文件中开启路由支持
2、使用路由
1.规则表达式配置路由
'my'=>'index/index',//静态地址路由 ':id/:num'=>'index/index',//动态地址路由 'year/:year/:month/:date'=>'index/index',//动态和静态混合地址路由 'year/:year\d/:month\d/:date\d'=>'index/index',//动态和静态混合地址路由
加上 \d代表类型只能是数字
'my/:id$'=>'index/index',// 加上$说明地址中只能是 my/1000 后面不能有其他内容了
2.正则表达式配置路由
'/^year\/(\d{4})\/(\d{2})\/(\d{2})/'=>'index/index?year=:1&month=:2&date=:3'
3、注意事项:
1.越复杂的路由越往前面放
'url_route_rules'=>array( 'my/:year/:month:/:day'=>'index/day', 'my/:id\d'=>'index/index', 'my/:name'=>'index/index', )
2.可以使用$作为完全匹配的路由规则
'url_route_rules'=>array( 'my/:id\d$'=>'index/index', 'my/:name$'=>'index/index', 'my/:year/:month:/:day$'=>'index/day', ),
3.用正则匹配的方式
'url_route_rules'=>array( '/^my\/(\d+)$/'=>'index/index?id=:1', '/^my\/(\w+)$/'=>'index/index?name=:1', '/^my\/(\d{4})\/(\d{2})\/(\d{2})$/'=>'index/day?year=:1&month=:2&day=:3', ),
四:url重写
(1):将apache---〉httpd.conf下的rewrite开启:
#loadmodule rewrite_module modules/mod_rewrite.so 将 # 去掉即可
(2):allowoverride none 将none改为 all:即
<directory "d:/wamp/cgi-bin"> allowoverride none options none require all granted</directory>
(3):确保url_model设置为2(不用修改)
(4):把下面的内容保存为.htaccess文件放到入口文件的同级目录下
<ifmodule mod_rewrite.c> rewriteengine on rewritecond %{request_filename} !-d rewritecond %{request_filename} !-f rewriterule ^(.*)$ index.php/$1 [qsa,pt,l]</ifmodule>
然后重启apache
推荐学习:《php视频教程》
以上就是php怎么设置url模式的详细内容。
其它类似信息

推荐信息