【问题标题】:.htaccess SSL and Non SSL with www to non www redirect.htaccess SSL 和非 SSL 与 www 到非 www 重定向
【发布时间】:2014-11-24 06:10:19
【问题描述】:

我在这里使用了各种答案来创建下面的 .htaccess 脚本。我需要脚本做的是

1) 将所有 www 重定向到非 www(例如 www.example.com 到 example.com)

2) 在页面末尾丢失 php(例如 www.example.com/store.php 到 example.com/store)

3) 将特定页面的所有点击重定向到安全的 HTTPS 版本(例如 http://www.example.com/secure-pagehttps://example.com/secure-page

除了能够将 www 重定向到 https 页面的非 www 之外,我已经设法完成了上述所有操作。以下是我的代码

RewriteEngine On
RewriteBase /
Options +FollowSymlinks

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

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L] 

RewriteCond %{HTTPS} off
RewriteRule ^secure-page\.php$ https://example.com/secure-page [L,R=301]

RewriteCond %{HTTPS} off
RewriteRule ^secure-page/ secure-page [R=301,L]

RewriteCond %{HTTPS} on
RewriteRule ^secure-page/ secure-page [R=301,L]

我已经尝试添加该行

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

但这似乎不起作用。

【问题讨论】:

    标签: apache .htaccess redirect ssl https


    【解决方案1】:

    0) 重写引擎和选项:

    RewriteEngine On
    RewriteBase /
    Options +FollowSymlinks +MultiViews
    

    1) 将 www 重定向到非 www :

    RewriteCond %{HTTP_HOST} ^www\.
    RewriteRule (.*) http://example.com%{REQUEST_URI} [L,R=301]
    

    2) 使用MultiViews 选项。

    3) 重定向到 https :

    RewriteCond %{HTTPS} off
    RewriteRule ^secure-page https://example.com/secure-page [L,R=301]
    

    【讨论】:

      猜你喜欢
      • 2019-01-28
      • 2016-04-02
      • 2018-09-11
      • 1970-01-01
      • 1970-01-01
      • 2010-12-01
      • 1970-01-01
      • 2013-10-04
      • 2016-12-30
      相关资源
      最近更新 更多