php - 为什么.htaccess重定向不起效果?
给我你的怀抱
给我你的怀抱 2017-05-16 13:05:35
0
2
571
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{http_host} ^xxx.com [NC]
RewriteRule ^(.*)$ http://www.xxx.com/$1 [L,R=301]

不是在网站根目录新建.htaccess吗?访问xxx.com还是不跳转带www
我的是阿里云服务器 装的tomcat.

给我你的怀抱
给我你的怀抱

Antworte allen(2)
某草草

你应该还要配置一下你服务器那一块的设置。apache 下需要添加allowoverride all。

曾经蜡笔没有小新

看代码好像只是为域名加上www.前缀,以下是我常用的代码:

RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
 
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} !^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]

如果还不行,也许你的apache并没有开rewrite或者没有支持.htaccess。


tomcat是需要配合apache使用的,tomcat只是个Servlet容器,它不处理HTTP协议。htaccess是apache的配置,没有配apache当然无法生效。

Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage