首页 文章

.htaccess SSL和非SSL,www到非www重定向

提问于
浏览
1

我在这里使用了各种答案来创建下面的.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重定向到非www for https页面 . 以下是我的代码

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]

但这似乎不起作用 .

1 回答

  • 0

    0)RewriteEngine和选项:

    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]
    

相关问题