【发布时间】: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-page 到 https://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