首页 > 开发 > Apache > 正文

apache中虚拟主机与伪静态配置方法

2020-10-12 18:50:34
字体:
来源:转载
供稿:网友

在apache安装根目录中找到conf/httpd.conf文件,然后打开这个文件最下边有一行

# virtual hosts

include conf/extra/httpd-vhosts.conf

看include conf/extra/httpd-vhosts.conf 这一行是否被注释掉,如果被注释掉,请取消注释。

然后打开conf/extra/httpd-vhosts.conf 这个文件,在文件中新建虚拟机,比如要绑定域名为www.Cuoxin.com

  1. <virtualhost *:80> 
  2.     documentroot "/home/aaa.com"   //网站所在的全路径 
  3.     servername www.Cuoxin.com  //要绑定的域名 
  4.     directoryindex index.html //默认打开的首页文件 
  5. </virtualhost> 

apache 伪静态设置

一 打开 apache 的配置文件 httpd.conf 。

二 将#loadmodule rewrite_module modules/mod_rewrite前面的#去掉

三 在 httpd.conf中添加:

  1. <ifmodule mod_rewrite.c> 
  2.     rewriteengine on 
  3.     #rewritecond %{env:script_url} (?:index|dispbbs)[-0-9]+.html 
  4.     rewriterule ^(.*?(?:index|dispbbs))-([-0-9]+).html$ $1.?__is_apache_rewrite=1&__rewrite_arg=$2 
  5. </ifmodule> 

四 要实现帖子url到php帖子的映射,在 第三步的<ifmodule mod_rewrite.c>和</ifmodule>之间添加:

  1. rewritemap tolowercase int:tolower 
  2.    rewritecond %{query_string} (?:boardid|page|id|replyid|star|skin)=d+ [nc] 
  3.    rewriterule ^(.*(?:index|dispbbs)).asp$ $1.php?${tolowercase:%{query_string}}&__is_apache_rewrite=1 

五 保存httpd.conf并重启apache。

根据不同的服务,不同的安装,apache下面的conf/httpd.conf会不相同,所以网上很多新建站的朋友,在用别人成功的方法设置自己的站点时,设置失败。下面我先说明一下正确的设置方法,再讲解失败的原因。

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表