Options +FollowSymLinks
RewriteEngine on
RewriteCond %{http_host} ^xxx.com [NC]
RewriteRule ^(.*)$ http://www.xxx.com/$1 [L,R=301]
Shouldn’t you create a new .htaccess in the root directory of the website? When accessing xxx.com, you should not jump to www
I have tomcat installed on Alibaba Cloud Server.
某草草2017-05-16 13:07:35
You should also configure the settings of your server. Allowoverride all needs to be added under apache.
曾经蜡笔没有小新2017-05-16 13:07:35
Looking at the code, it seems that it just adds the www. prefix to the domain name. The following is the code I commonly use:
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/ [R=301,L]
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} !^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/ [R=301,L]
If it still doesn’t work, maybe your apache does not have rewrite enabled or does not support .htaccess.
Tomcat needs to be used with apache. Tomcat is just a Servlet container. It does not handle the HTTP protocol. htaccess is the configuration of apache. Of course, it will not take effect without apache configuration.