PageAdmin网站内容管理系统(CMS)交流论坛

注册

 

QQ登录

只需一步,快速开始

发新话题 回复该主题

通过重写组件为手机站绑定二级域名到子目录 [复制链接]

1#
名秀办公家具[url=http://www.mxbgjj.com/]http://www.mxbgjj.com/[/url]
修改WEB.config 通过URL重写实现了手机站绑定二级域名
/mobile  为手机站子目录
手机域名m.mxbgjj.com解析到主机上
<rule name="m">
                    <match url="(.*)" />
                    <conditions>
                        <add input="{HTTP_HOST}" pattern="^m.xxxx.com$" />
                        <add input="{REQUEST_URI}" pattern="(mobile|e)/" negate="true" /> //域名后不为/mobile或/e  重写url  即m.xxxx.com 实际访问的是m.xxxx.com/mobile/
                    </conditions>
                    <action type="Rewrite" url="/mobile/{R:1}" /> //获取域名后的地址
                </rule>


---------------------------------------------------------------------------
301重定向[[url]www.xxxx.com/mobile/[/url] 访问 m.xxxx.com
<rule name="301" stopProcessing="true">
                    <match url="(.*)" />
                    <conditions logicalGrouping="MatchAll">
                        <add input="{HTTP_HOST}" pattern="^[url]www.xxxx.com[/url]" />
                        <add input="{REQUEST_URI}" pattern="^/mobile/" />
                    </conditions>
                    <action type="Redirect" url="http://m.xxxx.com/" appendQueryString="false" />
                </rule>
设置完后即可以通过m.xxxx.com访问/mobile
分享 转发
TOP
2#

兄弟,再详细点,我正在想怎样实现这个效果,怎么改了之后出现500错误,是两段都加上,还是随便加一段,还有加我web.config的哪里?
TOP
3#

另外,手机版的伪静态你怎么做的?也是用web.config做的吗?可否把你的web.config去掉个人信息共享下
TOP
4#

我用官网isapi筛选的方式做伪静态,手机站共享主战数据,主站伪静态正常,手机站伪静态为什么是这种格式wap/lwzx/lwfw/index.aspx?id=2962
TOP
5#

   <rewrite>
            <rules>
                <rule name="列表页静态" enabled="true">
                    <match url="^([^.]+)/list_([0-9]+).html$" ignoreCase="false" />
                    <action type="Rewrite" url="{R:1}/index.aspx?page={R:2}" appendQueryString="false" />
                </rule>
                <rule name="www伪静态" enabled="true">
                    <match url="([A-Za-z\d_]+)/detail_([0-9]+).html$" ignoreCase="true" />
                    <action type="Rewrite" url="/e/aspx/detail.aspx?table={R:1}&amp;id={R:2}" appendQueryString="false" />
<conditions>
                        <add input="{HTTP_HOST}" pattern="^[url]www.xxxx.com[/url]" />
                    </conditions>
                </rule>
    <rule name="m伪静态" enabled="true">
                    <match url="([A-Za-z\d_]+)/detail_([0-9]+).html$" ignoreCase="true" />
                    <action type="Rewrite" url="/e/aspx/detail.aspx?table={R:1}&amp;id={R:2}&amp;site=7" appendQueryString="false" />    ///手机站伪静态  url重写时传了一个参数过去。 site=7
                    <conditions>
                        <add input="{HTTP_HOST}" pattern="^m.xxxx.com" />
                    </conditions>
                </rule>
                    <rule name="手机站M" stopProcessing="false">
                    <match url="(.*)" />
                    <conditions>
                        <add input="{HTTP_HOST}" pattern="^m.xxxx.com$" />
                        <add input="{REQUEST_URI}" pattern="(mobile|e)/" negate="true" />
                    </conditions>
                    <action type="Rewrite" url="/mobile/{R:1}" appendQueryString="false" />
                </rule>
            </rules>
        </rewrite>




override protected void OnInit(EventArgs e)
{
  string Table=Request.QueryString["table"];
  string Id=Request.QueryString["id"];
  string site=Request.QueryString["site"];
  if(IsStr(Table) && IsNum(Id))
    {
     Conn Myconn=new Conn();
     OleDbConnection conn=Myconn.OleDbConn();//获取OleDbConnection
     conn.Open();
     string sql="select id from pa_table where thetable='"+Table+"'";
     OleDbCommand comm=new OleDbCommand(sql,conn);
     OleDbDataReader dr=comm.ExecuteReader();
     if(!dr.Read())
      {
        dr.Close();
        conn.Close();
        Response.Write("此信息未被调用!");
      }
     dr.Close();
     sql="select site_id,lanmu_id,sublanmu_id , sort_id from "+Table+" where id="+Id;
     comm=new OleDbCommand(sql,conn);
     dr=comm.ExecuteReader();
     if(dr.Read())
      {
         string sort_id=dr["sort_id"].ToString();
        if(site == null){
        Load_PageAdmin(int.Parse(dr["site_id"].ToString()),int.Parse(dr["lanmu_id"].ToString()),int.Parse(dr["sublanmu_id"].ToString()));
        }
        else
        {
            dr.Close();
            sql="select id,lanmu_id from pa_sublanmu  where sort_id= "+sort_id+" and site_id = "+site;                                  //判断是手机站的url 查询手机站的栏目id
            comm=new OleDbCommand(sql,conn);
            dr=comm.ExecuteReader();
            dr.Read();
            Load_PageAdmin(int.Parse(site.ToString()),int.Parse(dr["lanmu_id"].ToString()),int.Parse(dr["id"].ToString()));
        }
      }
     else
      {
        dr.Close();
        conn.Close();
        Response.Redirect("/");
      }
     conn.Close();
    }
  else
    {
      Response.Redirect("/");
    }
}
TOP
6#

太感谢了,这就试试去
TOP
7#

奇怪了,照着你这个改了detail.aspx和webconfig,主站伪静态正常,手机站可以跳转,但是伪静态的格式还是不对
TOP
8#

手机站也设置为伪静态,
TOP
9#

手机站栏目中 调用目标分类的目标子栏目不勾选
TOP
10#

不勾选的话,手机版地址形式上对了,但是不能访问,提示错误:不存在此行/列的数据。
TOP
11#

我手机站用的是主站的数据
TOP
12#

回复 11楼tjgeass的帖子

我也是和主站共用数据。。。实在是弄不了,搞了几天,累死了
TOP
13#

哈哈,终于发现什么原因了,和是否作为调用目标没关系,是因为我的手机版不是调用的最终类,sort_id对不上,还有手机版用的模型也也要改一下,搞定了,谢谢
TOP
发新话题 回复该主题