将http://www.example.com重定向到http://example.com

编程入门 行业动态 更新时间:2024-10-24 04:37:45
本文介绍了将www.example重定向到example的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如何将 www.example 重定向到 example 在Tomcat中?所有文档都集中在Apache上,但是我正在托管Java应用.

How do I redirect www.example to example in Tomcat? All the documentation focuses on Apache, but I'm hosting a Java app.

推荐答案

Apache

这应该是

# .htaccess file contents # Apache has the same docroot as the Java web app. # Java webapp is running on port 8084 <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / # For sites running on a port other than 80 RewriteCond %{HTTP_HOST} !^domain\ [NC] RewriteCond %{HTTP_HOST} !^$ RewriteCond %{SERVER_PORT} !^80$ RewriteRule ^/(.*) domain:%{SERVER_PORT}/$1 [L,R] # And for a site running on port 80 RewriteCond %{HTTP_HOST} !^domain\ [NC] RewriteCond %{HTTP_HOST} !^$ RewriteRule ^/(.*) domain/$1 [L,R] </IfModule>

httpd.apache/docs/2.0/misc/rewriteguide.html

您可以在Tomcat中使用 UrlRewriteFilter .这样的规则应该在/WEB-INF/urlrewrite.xml 中为您工作:

You can use UrlRewriteFilter in Tomcat. A rule like this should work for you in /WEB-INF/urlrewrite.xml:

<rule enabled="true"> <name>Force HTTPS example</name> <note>Automatically redirects user requests.</note> <from>domain/(.*)$</from> <to type="permanent-redirect" last="true">www.domain/</to> </rule>

不确定我是否做错字,写在头上

Not sure if I made typo's, wrote this on top of head

更多推荐

将http://www.example.com重定向到http://example.com

本文发布于:2023-11-01 11:37:28,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1549239.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:重定向   http   www

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!