您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

详解thinkphp5.1的URL重写,伪静态设置

2024/6/15 2:32:24发布48次查看
下面由thinkphp教程栏目给大家介绍thinkphp5.1的url重写,伪静态设置方法,希望对需要的朋友有所帮助!
thinkphp 5.1 可以通过url重写隐藏应用的入口文件index.php(也可以是其它的入口文件,但url重写通常只能设置一个入口文件),下面是相关服务器的配置参考:
apache
httpd.conf配置文件中加载了mod_rewrite.so模块
allowoverride none 将none改为 all
把下面的内容保存为.htaccess文件放到应用入口文件的同级目录下
<ifmodule mod_rewrite.c> options +followsymlinks -multiviews rewriteengine on rewritecond %{request_filename} !-d rewritecond %{request_filename} !-f rewriterule ^(.*)$ index.php/$1 [qsa,pt,l]</ifmodule>
iis
如果你的服务器环境支持isapi_rewrite的话,可以配置httpd.ini文件,添加下面的内容:
rewriterule (.*)$ /index\.php\?s=$1 [i]
在iis的高版本下面可以配置web.config,在中间添加rewrite节点:
rewriterule (.*)$ /index\.php\?s=$1 [i]<rewrite> <rules> <rule name="orgpage" stopprocessing="true"> <match url="^(.*)$" /> <conditions logicalgrouping="matchall"> <add input="{http_host}" pattern="^(.*)$" /> <add input="{request_filename}" matchtype="isfile" negate="true" /> <add input="{request_filename}" matchtype="isdirectory" negate="true" /> </conditions> <action type="rewrite" url="index.php/{r:1}" /> </rule> </rules> </rewrite>
rewriterule (.*)$ /index\.php\?s=$1 [i]
nginx
在nginx低版本中,是不支持pathinfo的,但是可以通过在nginx.conf中配置转发规则实现:
location / { // …..省略部分代码 if (!-e $request_filename) { rewrite ^(.*)$ /index.php?s=/$1 last; }}
其实内部是转发到了thinkphp提供的兼容url,利用这种方式,可以解决其他不支持pathinfo的web服务器环境。
如果你的应用安装在二级目录,nginx的伪静态方法设置如下,其中youdomain是所在的目录名称。
http://servername/模块/控制器/操作/[参数名/参数值...]
原来的访问url:
http://servername/index.php/模块/控制器/操作/[参数名/参数值...]
设置后,我们可以采用下面的方式访问:
http://servername/模块/控制器/操作/[参数名/参数值...]
如果你没有修改服务器的权限,可以在index.php入口文件做修改,这不是正确的做法,并且不一定成功,视服务器而定,只是在框架执行前补全$_server['path_info']参数。
$_server['path_info'] = $_server['request_uri' ];
以上就是详解thinkphp5.1的url重写,伪静态设置的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product