<?php 
	include './head.php';
  if(rootPath()){
    $path = rootPath().'/';
  }
?>

<div class="layui-row layui-col-space15">
        <div class="layui-col-md8 layui-col-md-offset2">
            <div class="layui-card" style="border-radius: 20px;">
              <div class="layui-card-header">
                <h3 style="padding-top: 3px;color: hsl(230,10%,40%);"><b>伪静态配置</b></h3>
              </div>
              <div class="layui-card-body">
                <div class="layui-form layui-form-pane">
                  <div class="layui-form-item" pane="">
                    <label class="layui-form-label">伪静态</label>
                    <div class="layui-input-block">
                      <?php 
                        if(conf('rewrite')){
                          $checked = 'checked';
                        }
                      ?>
                      <input type="checkbox" <?php echo $checked; ?>  name="rewrite" lay-skin="switch" lay-filter="rewrite">
                    </div>
          </div>
          请将以下内容添加到伪静态规则
         <?php if(webServer()=='nginx'){?>
   <pre class="layui-code">
location / {
 if (!-e $request_filename) {
   rewrite ^/<?php echo $path;?>(.[a-zA-Z0-9\-\_]+)/(.[0-9]*).html$ /<?php echo $path;?>index.php?class=$1&view=$2 last;
 }
}</pre>  
 <?php }elseif(webServer()=='apache'){?>
  <pre class="layui-code">
RewriteRule '^/<?php echo $path;?>(.[a-zA-Z0-9\-\_]+)/(.[0-9]*).html$$' /<?php echo $path;?>index.php?class=$1&view=$2 [L] </pre> 
<?php }else{
  echo '<pre class="layui-code">为匹配到相关规则</pre> ';
}?>
      
           <center><button class="layui-btn" lay-submit="" lay-filter="configEdit">确定保存</button></center>
    </div>
<script src="../public/static/layuiadmin/layui/layui.all.js"></script>
  <script>
  layui.config({
      base: '../public/static/layuiadmin/' //静态资源所在路径
    }).extend({
      index: 'lib/index' //主入口模块
    }).use(['index','form','table'], function(){
      var $ = layui.$
      ,table = layui.table
      ,layedit = layui.layedit
      ,laydate = layui.laydate
      ,form = layui.form
      ,admin = layui.admin
      ,element = layui.element
      ,layer = layui.layer;
      element.render();

      layui.code({
        title: '当前服务器Web软件为：<font color="red"><b><?php echo webServer();?></b></font>',
        about:false
      });

       form.on('submit(configEdit)', function(data){
          if(data.field.rewrite){
            rewrite = 1;
          }else{
            rewrite = 0;
          }
          var load = layer.load({time:false});
          $.ajax({
                url: "./ajax.php?act=configEdit",
                data: {rewrite},
                type: "POST",
                dataType: "json",
                success: function(data){
                    layer.close(load);
                    if(data.code==1){
                      layer.msg(data.msg,{icon:6});
                    }else{
                      layer.msg(data.msg,{icon:5});
                    }
                },
                error: function(data){
                    layer.close(load);
                    layer.msg("未知错误");
                }
            });
        });
  });
  </script>
<?php 
	include 'foot.php';
?>