suchen

Heim  >  Fragen und Antworten  >  Hauptteil

php - 为什么.htaccess重定向不起效果?

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{http_host} ^xxx.com [NC]
RewriteRule ^(.*)$ http://www.xxx.com/$1 [L,R=301]

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

给我你的怀抱给我你的怀抱2840 Tage vor577

Antworte allen(2)Ich werde antworten

  • 某草草

    某草草2017-05-16 13:07:35

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

    Antwort
    0
  • 曾经蜡笔没有小新

    曾经蜡笔没有小新2017-05-16 13:07:35

    看代码好像只是为域名加上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当然无法生效。

    Antwort
    0
  • StornierenAntwort