<title>URL伪静态</title>
  
<div class="layui-card layadmin-header">
  <div class="layui-breadcrumb" lay-filter="breadcrumb">
    <a lay-href="">主页</a>
    <a><cite>问答管理</cite></a>
    <a><cite>基本设置</cite></a>
    <a><cite>URL伪静态</cite></a>
  </div>
</div>

  <div class="layui-fluid">
    <div class="layui-row layui-col-space15">
    
    <div class="layui-col-md12">
      <div class="layui-card">
    	<div class="layui-card-header">网址后缀</div>
        <div class="layui-card-body">

          <form class="layui-form" lay-filter="J_ajaxForm" action="{:url('wendasns/config/urlsuffix')}" method="post">
          
        <div class="layui-form-item">
          <label class="layui-form-label">后缀名</label>
          <div class="layui-input-block">
            <div class="layui-input-inline">
            	<input type="text" name="suffix" autocomplete="off" value="{:config('route.url_html_suffix')}" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">如: html、shtml、htm、jsp、asp等，暂不支持设置成php</div>
          </div>
        </div>
            
            <div class="layui-form-item">
              <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="J_ajax_submit_btn"><i class="layui-icon layui-icon-ok-circle"></i>提交</button>
              </div>
            </div>
          </form>
          
        </div>
      </div>
    </div>
    
      <div class="layui-col-md12">
        <div class="layui-card">

     <div class="layui-card-header">URL伪静态</div>

    <!--列表-->
    <div class="layui-card-body">
    
    <blockquote class="layui-elem-quote layui-quote-nm">
    <p>此功能把站点的URL转换成静态链接的方式，更容易被搜索引擎收录。</p>
<p>开启伪静态功能后，需要开启服务器的rewrite模块</p>

          </blockquote>

      <div style="padding-bottom: 10px;">
        <a href="#J_view" class="layui-btn J_popup" title="添加路由"><i class="layui-icon layui-icon-add-circle"></i>添加</a>
        <a href="wendasns/rewrite/remove" class="layui-btn J_req" title="确定要删除吗？"><i class="layui-icon layui-icon-delete"></i>删除</a>
      </div>
      
      <!--表格-->
      <table id="J_table_list" lay-filter="J_table_list" url="{:url('wendasns/rewrite/edit')}"></table>

    </div>
    
  </div>
</div>

    <div class="layui-col-md12">
      <div class="layui-card">
        <div class="layui-card-header">使用方法</div>
        <div class="layui-card-body">
          <h3>[ Apache ]</h3>
          <ol><li><code>httpd.conf</code>配置文件中加载了<code>mod_rewrite.so</code>模块</li><li><code>AllowOverride None</code> 将<code>None</code>改为 <code>All</code></li><li>把下面的内容保存为<code>.htaccess</code>文件放到应用入口文件的同级目录下</li></ol>
          <pre class="layui-code" lay-skin="notepad"><code class="highlight-container"><span class="token operator">&lt;</span>IfModule mod_rewrite<span class="token punctuation">.</span>c<span class="token operator">&gt;</span>
  Options <span class="token operator">+</span>FollowSymlinks <span class="token operator">-</span>Multiviews
  RewriteEngine On

  RewriteCond <span class="token operator">%</span><span class="token punctuation">{</span>REQUEST_FILENAME<span class="token punctuation">}</span> <span class="token operator">!</span><span class="token operator">-</span>d
  RewriteCond <span class="token operator">%</span><span class="token punctuation">{</span>REQUEST_FILENAME<span class="token punctuation">}</span> <span class="token operator">!</span><span class="token operator">-</span>f
  RewriteRule <span class="token operator">^</span><span class="token punctuation">(</span><span class="token punctuation">.</span><span class="token operator">*</span><span class="token punctuation">)</span>$ index<span class="token punctuation">.</span>php?<span class="token operator">/</span>$<span class="token number">1</span> <span class="token punctuation">[</span>QSA<span class="token punctuation">,</span>PT<span class="token punctuation">,</span>L<span class="token punctuation">]</span>
<span class="token operator">&lt;</span><span class="token operator">/</span>IfModule<span class="token operator">&gt;</span>
</code></pre>

        <h3>[ IIS ]</h3>
        <p>如果你的服务器环境支持<code>ISAPI_Rewrite</code>的话，可以配置<code>httpd.ini</code>文件，添加下面的内容：</p>
        <pre class="layui-code" lay-skin="notepad"><code class="ಠhighlight-container">RewriteRule <span class="token punctuation">(</span><span class="token punctuation">.</span><span class="token operator">*</span><span class="token punctuation">)</span>$ <span class="token operator">/</span>index\<span class="token punctuation">.</span>php\<span class="token operator">?</span>s<span class="token operator">=</span>$<span class="token number">1</span> <span class="token punctuation">[</span>I<span class="token punctuation">]</span>
</code></pre>
<p>在IIS的高版本下面可以配置<code>web.Config</code>，在中间添加<code>rewrite</code>节点：</p>
<pre class="layui-code" lay-skin="notepad"><code class="ಠhighlight-container"><span class="token operator">&lt;</span>rewrite<span class="token operator">&gt;</span>
 <span class="token operator">&lt;</span>rules<span class="token operator">&gt;</span>
 <span class="token operator">&lt;</span>rule name<span class="token operator">=</span><span class="token string">"OrgPage"</span> stopProcessing<span class="token operator">=</span><span class="token string">"true"</span><span class="token operator">&gt;</span>
 <span class="token operator">&lt;</span>match url<span class="token operator">=</span><span class="token string">"^(.*)$"</span> <span class="token operator">/</span><span class="token operator">&gt;</span>
 <span class="token operator">&lt;</span>conditions logicalGrouping<span class="token operator">=</span><span class="token string">"MatchAll"</span><span class="token operator">&gt;</span>
 <span class="token operator">&lt;</span>add input<span class="token operator">=</span><span class="token string">"{HTTP_HOST}"</span> pattern<span class="token operator">=</span><span class="token string">"^(.*)$"</span> <span class="token operator">/</span><span class="token operator">&gt;</span>
 <span class="token operator">&lt;</span>add input<span class="token operator">=</span><span class="token string">"{REQUEST_FILENAME}"</span> matchType<span class="token operator">=</span><span class="token string">"IsFile"</span> negate<span class="token operator">=</span><span class="token string">"true"</span> <span class="token operator">/</span><span class="token operator">&gt;</span>
 <span class="token operator">&lt;</span>add input<span class="token operator">=</span><span class="token string">"{REQUEST_FILENAME}"</span> matchType<span class="token operator">=</span><span class="token string">"IsDirectory"</span> negate<span class="token operator">=</span><span class="token string">"true"</span> <span class="token operator">/</span><span class="token operator">&gt;</span>
 <span class="token operator">&lt;</span><span class="token operator">/</span>conditions<span class="token operator">&gt;</span>
 <span class="token operator">&lt;</span>action type<span class="token operator">=</span><span class="token string">"Rewrite"</span> url<span class="token operator">=</span><span class="token string">"index.php/{R:1}"</span> <span class="token operator">/</span><span class="token operator">&gt;</span>
 <span class="token operator">&lt;</span><span class="token operator">/</span>rule<span class="token operator">&gt;</span>
 <span class="token operator">&lt;</span><span class="token operator">/</span>rules<span class="token operator">&gt;</span>
 <span class="token operator">&lt;</span><span class="token operator">/</span>rewrite<span class="token operator">&gt;</span>
</code></pre>

          <h3>[ Nginx ]</h3>
           <p>在Nginx低版本中，是不支持PATHINFO的，但是可以通过在<code>Nginx.conf</code>中配置转发规则实现：</p>
           <pre class="layui-code" lay-skin="notepad"><code class="ಠhighlight-container">location <span class="token operator">/</span> <span class="token punctuation">{</span> <span class="token comment"></span>
   <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token operator">!</span><span class="token operator">-</span>e $request_filename<span class="token punctuation">)</span> <span class="token punctuation">{</span>
   		rewrite  <span class="token operator">^</span><span class="token punctuation">(</span><span class="token punctuation">.</span><span class="token operator">*</span><span class="token punctuation">)</span>$  <span class="token operator">/</span>index<span class="token punctuation">.</span>php<span class="token operator">?</span>s<span class="token operator">=</span><span class="token operator">/</span>$<span class="token number">1</span>  last<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre>
        </div>
      </div>
    </div>


  </div>
</div>

<script type="text/html" id="J_table_checkbox_tpl">
  <input type="checkbox" name="status" value="{{ d.id || 0}}" class="layui-input" lay-text="是|否" lay-skin="switch" {{ d.status?'checked':''}} lay-filter="J_checkbox_enable">
</script>

<script type="text/html" id="J_table_tool">
  <a href="#J_view" class="layui-btn layui-btn-normal layui-btn-xs" lay-event="popup" title="编辑路由"><i class="layui-icon layui-icon-edit"></i>编辑</a>
  <a href="wendasns/rewrite/remove" class="layui-btn layui-btn-danger layui-btn-xs" lay-event="req" title="确定要删除吗？"><i class="layui-icon layui-icon-delete"></i>删除</a>
</script>

<script>
;!function(){
  var table = layui.table
  ,form = layui.form;
  form.render();
  //执行渲染
table.render({
  elem: '#J_table_list'
  ,url: '{:url('wendasns/rewrite/list')}'
  ,cols: [[
      {type: 'checkbox'}
      ,{field:'subject',title:'页面',width:150}
      ,{field:'description',title:'可用url参数',minWidth:150}
      ,{field:'rule',title:'url格式',minWidth:150,edit:'text',templet:function(d){return layui.$("<div/>").text(d.rule).html();}}
      ,{field:'controller',title:'应用',minWidth:120,edit:'text'}
      ,{field:'status',title:'启用',width:80,templet:'#J_table_checkbox_tpl',align:'center'}
      ,{title:'操作',width:150,align:'center',toolbar:'#J_table_tool'}
  ]]
  ,height: 'auto'
  ,text: {
    none: '暂无数据！'
  }
});

}();
</script>

<script type="text/html" id="J_view">
<form class="layui-form" style="padding: 20px 0 0 0;" action="{:url('wendasns/rewrite/dorun')}" method="post">
  <input type="hidden" name="id" value="{{ d.id || 0 }}">

  <div class="layui-form-item">
    <label class="layui-form-label">页面说明</label>
    <div class="layui-input-inline">
        <input type="text" name="subject" value="{{ d.subject || '' }}" class="layui-input">
    </div>
  </div>
  
  <div class="layui-form-item">
    <label class="layui-form-label">URL格式</label>
    <div class="layui-input-inline">
        <input type="text" name="rule" value="{{ d.rule || '' }}" class="layui-input">
    </div>
  </div>

  <div class="layui-form-item">
    <label class="layui-form-label">应用</label>
    <div class="layui-input-inline">
        <input type="text" name="controller" value="{{ d.controller || '' }}" class="layui-input">
    </div>
    <div class="layui-form-mid layui-word-aux">如：控制器名/方法名</div>
  </div>
  
  <div class="layui-form-item">
    <label class="layui-form-label">可用url参数</label>
    <div class="layui-input-inline">
        <input type="text" name="description" value="{{ d.description || '' }}" class="layui-input">
    </div>
    <div class="layui-form-mid layui-word-aux">如：[:id]：帖子ID</div>
  </div>
  
  <div class="layui-form-item">
    <label class="layui-form-label">启用</label>
    <div class="layui-input-block">
        <input type="radio" name="status" value="1" title="是" {{ d.status === 1 ? 'checked="checked"' : (typeof d.status==='undefined'&&'checked') }}>
        <input type="radio" name="status" value="0" title="否" {{ d.status === 0 ? 'checked="checked"' : '' }}>
    </div>
  </div>
  
  <div class="layui-form-item">
    <label class="layui-form-label"></label>
    <div class="layui-input-inline">
      <button lay-submit lay-filter="J_ajax_submit_btn" class="layui-btn"><i class="layui-icon layui-icon-ok-circle"></i>提交</button>
    </div>
  </div>
</form>
</script>