.htaccess Rewrite apache重写和配置

 1 首先:
 2 必须要空间支持 Rewrite 以及对站点目录中有 .htaccess 的文件解析,才有效.
 3 如何让空间支持Rewrite 和 .htaccess 的文件解析呢 往下看
 4 第一步:要找到apache安装目录下的httpd.cof文件,在里面找到
 5 <Directory />
 6     Options FollowSymLinks
 7     AllowOverride none
 8 </Directory>
 9 把none改all,
10 第二步:找到以下内容:
11 #LoadModule rewrite_module modules/mod_rewrite.so
12 改为
13 LoadModule rewrite_module modules/mod_rewrite.so
14 第三步:保存重启apache。
15 ok。
16 其次是.htaccess的书写规则:
17 .htaccess加入以下内容
18 RewriteEngine On
19 RewriteBase /
20 RewriteRule ^(.*)list-id([0-9]+)\.html$ $1/company/search.php?sectorid2=$2
21 RewriteRule ^(.*)cominfo-([a-z0-9]+)\.html$ $1/member/index.php?uid=$2&type=cominfo
22 RewriteRule ^(.*)list-([0-9]+)-([0-9]+)\.html$ $1/plus/list.php?typeid=$2&PageNo=$3
23 RewriteCond %{HTTP_HOST} ^[a-z0-9\-]+\.lujin\.com$
24 RewriteCond %{HTTP_HOST} !^(www|bbs)\.lujin\.com$
25 RewriteRule ^/?$ /%{HTTP_HOST}
26 RewriteRule ^/([a-z0-9\-]+)\.lujin\.com/?$ /member/index.php?uid=$1 [L]
27 
28 对上面的一些解释
29 RewriteRule ^(.*)list-id([0-9]+)\.html$ $1/company/search.php?sectorid2=$2
30 这条是把企业库的分类进行伪静态处理
31 原先假设访问地址为http://www.xxx.com/company/search.php?sectorid2=1
32 现在地址为http://www.xxx.com/list-id1.html
33 优点:1、伪静态处理加速搜索引擎收入
34 2、地址映射到根目录,增加权重,提高排名
35 3、也不知道还有什么……
36 
37 RewriteRule ^(.*)list-([0-9]+)-([0-9]+)\.html$ $1/plus/list.php?typeid=$2&PageNo=$3
38 这个是供求等分类的列表,和上面的原理类似,到页面相应修改即可
39 
40 下面是会员空间的二级域名方案
41 前提是把域名设置好泛解析
42 RewriteCond %{HTTP_HOST} ^[a-z0-9\-]+\.lujin\.com$
43 RewriteCond %{HTTP_HOST} !^(www|bbs)\.lujin\.com$
44 RewriteRule ^/?$ /%{HTTP_HOST}
45 RewriteRule ^/([a-z0-9\-]+)\.lujin\.com/?$ /member/index.php?uid=$1 [L]
46 假设原先的地址为http://www.xx.com/member/index.php?uid=admin
47 现在地址为http://admin.xx.com
48 你只要在你想出现的地方放上这个就可以,比如在列表页面可以用[field:writer/]获取用户名,那么就可以在列表页面直接链接会员空间,可以写成http://[field:writer/].xx.com

 

posted @ 2016-06-11 11:26  八路逆袭寡妇村  阅读(509)  评论(0编辑  收藏  举报
www.shiciyue.com