apache+tomcat二级域名+url重写
2015-06-07 12:39
537 查看
打开文件httpd.conf 文件(apache目录下面的文件)
以apache2.2.3设置为例,配置虚拟主机下的rewrite
在主目录里面需要添加代码 AllowOverride Options FileInfo
取消 LoadModule rewrite_module modules/mod_rewrite.so前面的 #
RewriteEngine On
RewriteRule ^(.*)show-([\d]+)-([\d]+)\.html$ $1/leafage.jsp?id=$2&page=$3
RewriteRule ^(.*)list-([\d]+)-([\d]+)\.html$ $1/list.jsp?id=$2&page=$3
RewriteRule ^(.*)show-([\d]+)\.html$ $1/show.jsp?id=$2
RewriteRule ^(.*)area-([\d]+)-(.+)\.html$ $1/area.jsp?id=$2&page=$3
重新启动Apache.
//经过上面的测试Tomcat和Apache可以通了
上面的配置还可以在虚拟主机里配置:如下:
原来配置:
apache httpd.conf:
include "conf/mod_jk.conf"
mod_jk.conf:
LoadModule jk_module modules/mod_jk-1.2.23-apache-2.2.x-linux-i686.so
JkWorkersFile conf/workers.properties
JkLogFile logs/mod_jk.log
JkLogLevel error
JkMount /*.jsp controller
JkMount /*.do controller
JkMount /*userAction.zip controller
...
JkMount /*.jar controller
JkMount /*.htm controller
JkMount /servlet/* controller
...........
作为虚拟主机配置文件httpd-vhost.conf的全局配置:
LoadModule jk_module modules/mod_jk-1.2.23-apache-2.2.x-linux-i686.so
JkWorkersFile conf/workers.properties
JkLogFile logs/mod_jk.log
JkLogLevel error
NameVirtualHost *:80
...
include "/usr/local/apache22/conf/mod_jk.conf"
同样上面的伪静态也可写在虚似主机里面如下:
DocumentRoot /home/www_php168
ServerName
RewriteEngine On
RewriteRule ^(.*)/list-([0-9]+)-([0-9]+).htm$ $1/list.php?fid=$2&page=$3
RewriteRule ^(.*)/bencandy-([0-9]+)-([0-9]+)-([0-9]+).htm$ $1/bencandy.php?
fid=$2&id=$3&page=$4
但是:伪静态时,show-100-33.html明明是要先转变成leafage.jsp?id=100&page=33的
可是Apache做了析解之后没有交给Tomcat处理也就是说伪静态也析解了,就是没有给Tomcat处理。
最后在上面的文章里面看到在RewriteRule最加下 [PT]如下:
RewriteRule ^(.*)show-([\d]+)-([\d]+)\.htm $1/leafage.jsp?id=$2&page=$3 [PT]
看来对RewriteRule参数还要研究
今天晚上折腾了一晚上终于把我们网站的二级域名问题和二级域名相关的问题解决了。并更新上去了。呵呵,小小总结一下。
第一部分,我的二级域名转向是在apache上配置的(其中的规则把我折腾了好几天)。
# JkMount /* worker1(用这个不能实现二级域名跳转,只有分着jKmount 才能行,原因不明。自己认为是如设置成该种形式,表示所有的情况都给tomcat处理,包括二级域名的解析)
JkMount /dwr/* worker1
JkMount /dwr/interface/* worker1
JkMount /*.jsp worker1
JkMount /*.do worker1
JkMount /*.html worker1
JkMount /*.htm worker1
DirectoryIndex index.jsp index.html
Options Indexes FollowSymLinks
AllowOverride none
Order allow,deny
Allow from all
DirectoryIndex index.jsp index.html welcome.jsp
RewriteEngine On
RewriteCond %{HTTP_HOST} !^(www|web)\.automation\.com\.cn$
RewriteRule ^/?$ /%{HTTP_HOST} (这一步很重要是把url链接改变成隐含参数的/bd.automation.com.cn的形式)
RewriteRule ^/bd\.automation\.com\.cn$ /industry.do?method=showIndustry&industryname=louyu [L] RewriteCond %{HTTP_HOST} !^(www|web)\.automation\.com\.cn$
RewriteRule (.*) /%{HTTP_HOST}/$1(这里url链接里面的参数是显示的,所以可以在下面那个规则中得到。这里费了我很长时间,真的觉得自己很笨,呵呵!)
RewriteRule ^/bd\.automation\.com\.cn/([a-zA-Z]+)$ /industry.do?method=getList&mainname=louyu&name=$1 [L]
ServerAdmin shiguoying@yeah.net
DocumentRoot "/usr/apps/apache-tomcat-6/apps/ROOT"
ServerName www.automation.com.cn
ServerAlias automation.com.cn
ErrorLog "logs/www.automation.com.cn-error_log"
CustomLog "logs/www.automation.com.cn-access_log" common
第二部分:在程序中用urlrewriter。jar包重写。其中和二级域名系相关的规则是
bd.automation.com.cn(这一点很重要,只有在匹配二级域名的时候起作用)
^/-do--list--id-(\d+).html$
/communityDetail.do?method=showArticleList&id=$1
第三部分:在程序中的链接中用程序控制二级域名相关的链接 用硬连接的形式改写。
public static String getUrl(HttpServletRequest request){
int ind = request.getRequestURL().toString().indexOf("/", 7);
String preurl = "";
if (ind == -1) {
preurl = "http://www.automation.com.cn";
} else {
preurl = request.getRequestURL().toString().substring(0, ind);
}
if (preurl.equals("http://bd.automation.com.cn")) {
preurl = "http://www.automation.com.cn";
}
return preurl;
}
在页面中
if "http://www.automation.com.cn".equals(preurl)
二级域名相关链接
else
正常没有重新的连接
打开文件httpd.conf 文件(apache目录下面的文件)
以apache2.2.3设置为例,配置虚拟主机下的rewrite
在主目录里面需要添加代码 AllowOverride Options FileInfo
取消 LoadModule rewrite_module modules/mod_rewrite.so前面的 #
RewriteEngine On
RewriteRule ^(.*)show-([\d]+)-([\d]+)\.html$ $1/leafage.jsp?id=$2&page=$3
RewriteRule ^(.*)list-([\d]+)-([\d]+)\.html$ $1/list.jsp?id=$2&page=$3
RewriteRule ^(.*)show-([\d]+)\.html$ $1/show.jsp?id=$2
RewriteRule ^(.*)area-([\d]+)-(.+)\.html$ $1/area.jsp?id=$2&page=$3
重新启动Apache.
//经过上面的测试Tomcat和Apache可以通了
上面的配置还可以在虚拟主机里配置:如下:
原来配置:
apache httpd.conf:
include "conf/mod_jk.conf"
mod_jk.conf:
LoadModule jk_module modules/mod_jk-1.2.23-apache-2.2.x-linux-i686.so
JkWorkersFile conf/workers.properties
JkLogFile logs/mod_jk.log
JkLogLevel error
JkMount /*.jsp controller
JkMount /*.do controller
JkMount /*userAction.zip controller
...
JkMount /*.jar controller
JkMount /*.htm controller
JkMount /servlet/* controller
...........
作为虚拟主机配置文件httpd-vhost.conf的全局配置:
LoadModule jk_module modules/mod_jk-1.2.23-apache-2.2.x-linux-i686.so
JkWorkersFile conf/workers.properties
JkLogFile logs/mod_jk.log
JkLogLevel error
NameVirtualHost *:80
...
include "/usr/local/apache22/conf/mod_jk.conf"
同样上面的伪静态也可写在虚似主机里面如下:
DocumentRoot /home/www_php168
ServerName
RewriteEngine On
RewriteRule ^(.*)/list-([0-9]+)-([0-9]+).htm$ $1/list.php?fid=$2&page=$3
RewriteRule ^(.*)/bencandy-([0-9]+)-([0-9]+)-([0-9]+).htm$ $1/bencandy.php?
fid=$2&id=$3&page=$4
但是:伪静态时,show-100-33.html明明是要先转变成leafage.jsp?id=100&page=33的
可是Apache做了析解之后没有交给Tomcat处理也就是说伪静态也析解了,就是没有给Tomcat处理。
最后在上面的文章里面看到在RewriteRule最加下 [PT]如下:
RewriteRule ^(.*)show-([\d]+)-([\d]+)\.htm $1/leafage.jsp?id=$2&page=$3 [PT]
看来对RewriteRule参数还要研究
今天晚上折腾了一晚上终于把我们网站的二级域名问题和二级域名相关的问题解决了。并更新上去了。呵呵,小小总结一下。
第一部分,我的二级域名转向是在apache上配置的(其中的规则把我折腾了好几天)。
# JkMount /* worker1(用这个不能实现二级域名跳转,只有分着jKmount 才能行,原因不明。自己认为是如设置成该种形式,表示所有的情况都给tomcat处理,包括二级域名的解析)
JkMount /dwr/* worker1
JkMount /dwr/interface/* worker1
JkMount /*.jsp worker1
JkMount /*.do worker1
JkMount /*.html worker1
JkMount /*.htm worker1
DirectoryIndex index.jsp index.html
Options Indexes FollowSymLinks
AllowOverride none
Order allow,deny
Allow from all
DirectoryIndex index.jsp index.html welcome.jsp
RewriteEngine On
RewriteCond %{HTTP_HOST} !^(www|web)\.automation\.com\.cn$
RewriteRule ^/?$ /%{HTTP_HOST} (这一步很重要是把url链接改变成隐含参数的/bd.automation.com.cn的形式)
RewriteRule ^/bd\.automation\.com\.cn$ /industry.do?method=showIndustry&industryname=louyu [L] RewriteCond %{HTTP_HOST} !^(www|web)\.automation\.com\.cn$
RewriteRule (.*) /%{HTTP_HOST}/$1(这里url链接里面的参数是显示的,所以可以在下面那个规则中得到。这里费了我很长时间,真的觉得自己很笨,呵呵!)
RewriteRule ^/bd\.automation\.com\.cn/([a-zA-Z]+)$ /industry.do?method=getList&mainname=louyu&name=$1 [L]
ServerAdmin shiguoying@yeah.net
DocumentRoot "/usr/apps/apache-tomcat-6/apps/ROOT"
ServerName www.automation.com.cn
ServerAlias automation.com.cn
ErrorLog "logs/www.automation.com.cn-error_log"
CustomLog "logs/www.automation.com.cn-access_log" common
第二部分:在程序中用urlrewriter。jar包重写。其中和二级域名系相关的规则是
bd.automation.com.cn(这一点很重要,只有在匹配二级域名的时候起作用)
^/-do--list--id-(\d+).html$
/communityDetail.do?method=showArticleList&id=$1
第三部分:在程序中的链接中用程序控制二级域名相关的链接 用硬连接的形式改写。
public static String getUrl(HttpServletRequest request){
int ind = request.getRequestURL().toString().indexOf("/", 7);
String preurl = "";
if (ind == -1) {
preurl = "http://www.automation.com.cn";
} else {
preurl = request.getRequestURL().toString().substring(0, ind);
}
if (preurl.equals("http://bd.automation.com.cn")) {
preurl = "http://www.automation.com.cn";
}
return preurl;
}
在页面中
if "http://www.automation.com.cn".equals(preurl)
二级域名相关链接
else
正常没有重新的连接
相关文章推荐
- nginx和Tomcat集成后发生的重定向问题分析和解决
- tomcat结合nginx使用小结
- Apache和Tomcat 实现泛域名解析的尝试
- Tomcat目录及配置文件解析
- 115 tomcat架构分析 (Session管理)
- tomcat通过conf-Catalina-localhost目录发布项目详解
- centos7安装tomcat8
- 关于intellij ide的tomcat的部署和配置
- 关闭Tomcat后再打开后,session还在,不进登陆页面
- tomcat与resin
- tomcat配置
- eclipse+tomcat 正常启动 但localhost报404
- 内存溢出之Tomcat内存配置-catalina.sh or catalina.bat
- JVM内存配置
- window tomcat 启动方法
- Tomcat java VM配置参数
- tomcat配置jenkins遇到的问题
- Tomcat学习之Wrapper
- 不配置环境变量运行tomcat
- Nginx+Tomcat在Windows下做负载均衡