【问题标题】:Remove index.php, force ssl, and redirect www to non www in .htaccess删除 index.php,强制使用 ssl,并将 www 重定向到 .htaccess 中的非 www
【发布时间】:2015-02-12 22:15:04
【问题描述】:

我很感激这些问题已经被完成了,但我似乎无法找到我需要的确切答案,所有最接近我的人都将非 www 重定向到 www,但我需要它反过来。

所以,我想做的是始终强制 www 为非 www,从 url 中重写 index.php,并始终强制站点为 SSL。

除了强制 SSL,我有以下所有功能,我尝试了很多不同的方法,但总是出现无限循环:

# Rewrite www to non www

<IfModule mod_rewrite.c>
  RewriteCond %{HTTPS} !=on
  RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
  RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]
</IfModule>

Rewrite the index.php out

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} !^/(favicon\.ico|apple-touch-icon.*\.png)$ [NC]
    RewriteRule (.+) index.php?p=$1 [QSA,L]
</IfModule>

【问题讨论】:

    标签: .htaccess mod-rewrite ssl


    【解决方案1】:

    尝试改变这个:

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

      RewriteCond %{HTTPS} !=on [OR]
      RewriteCond %{HTTP_HOST} ^www\. [NC]
      RewriteCond %{HTTP_HOST} ^(?:www\.|)(.+)$ [NC]
      RewriteRule ^ https://%1%{REQUEST_URI} [R=301,L]
    

    【讨论】:

      猜你喜欢
      • 2014-06-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-11
      • 1970-01-01
      • 1970-01-01
      • 2010-12-01
      相关资源
      最近更新 更多