问题:
在工程发布的时候,首页访问一般都是www.xxx.com,如果首页没有动态action数据那么没有什么问题;如果是action请求数据,则可能遇到访问不到内容的情况,比方:
1.访问www.xxx.com 无法访问
2.访问www.xxx.com 做跳转,url跳转到了www.xxx.com/index.html(或者其他的什么),可以访问到了,但是据说会影响网站的权重,至少不美观。
解决方案:
如果你采用的技术为是Java Struts Tomcat,有两种解决方式。
方式一 Tomcat:
通过web.xml的方式,配置为
1.修改web.xml
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>index.action</welcome-file>
</welcome-file-list>
其中前两个自然不必说了,是不需要action请求访问数据的方式。而index.action一般情况是无效的。那么需要下边一步
2.webcontent下面建立一个index.action的空文件,然后使用struts配置去跳转,不然web找不到index.action这个文件,会报404错误。解释:welcome-file-list的工作原理是,按照welcome-file的.list一个一个去检查是否web目录下面存在这个文件,如果存在,继续下面的工作(或者跳转到index.html页面,或者配置有struts的,会直接struts的过滤工作)
方式二 Structs:
通过urlrewrite的方式,配置为
<rule>
<note>首页</note>
<from>^/$</from>
<to type="forward">/index.action</to>
</rule>
这个方式也不陌生,主要from标签的url匹配表达式的写法即可。
方式三 Nginx:
这里,如果是单次重定向用 redirect, 如果永久跳转用 permanent,这里用 permanent
{
listen 80;
server_name xxx.com www.xxx.com;
index index.html index.php;
root /data/www/wwwroot;
if ($http_host !~ "^www.xxx.com$") {
rewrite ^(.*) http://www.xxx.com$1 permanent;
}
........................
}
参考:
http://blog.youkuaiyun.com/fruithardcandy/article/details/7275019
http://bbs.powereasy.net/forum67/thread-413426-1-575.aspx
http://honda418.iteye.com/blog/835246
PHP参见:
http://www.haoxuee.com/IT/dedecms/132033.html