Automatically add the "www" subdomain for my webapp
How can I set Tomcat to automatically redirect to "www"? I want that if a user enters my domain like:
mydomain.com
he will be redirected to: www.mydomain.com
If you are using Apache, simple do (on htaccess):
RewriteEngine On
RewriteCond %{HTTP_HOST} ^yourdomain.com
RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [R=301]
This way you make sure anything that is not using www starts using
UPDATE As you mentioned you don't have apache, I remembered I used this about a year ago. It does pretty much the same as mod_rewrite, and is fully supported by Tomcat. I used it with resin though, but I know it works the same way.
Greatest thing about it, is that it also runs on "mod_rewrite style", as you can see here. The only reason why I didn't continue using it, is because it will end up doing it at a server level, as opposed to a webserver level. Meaning it will call the JVM to interpret the redirect.
It works the same way though, and as mentioned before, can sue exactly the same thing you'd use on Apache.
tuckey url重写过滤器可以像这样使用来做适当的重定向:
<rule>
<name>Canonical Hostnames</name>
<condition name="host" operator="notequal">^www.mydomain.com</condition>
<condition name="host" operator="notequal">^$</condition>
<from>^/(.*)</from>
<to type="redirect" last="true">http://www.mydomain.com/$1</to>
</rule>
wwwizer.com offers free naked domain redirect http://wwwizer.com/naked-domain-redirect
Point your naked domain like mysite.com to their IP, and they'll do a 301 redirect to www.mysite.com
Using a 301 redirect is the recommended way for SEO optimization.
链接地址: http://www.djcxy.com/p/89058.html上一篇: 基于tomcat正文重定向请求